| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 96 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 97 #include "third_party/WebKit/public/web/WebView.h" | 97 #include "third_party/WebKit/public/web/WebView.h" |
| 98 #include "ui/base/layout.h" | 98 #include "ui/base/layout.h" |
| 99 #include "ui/base/resource/resource_bundle.h" | 99 #include "ui/base/resource/resource_bundle.h" |
| 100 #include "v8/include/v8.h" | 100 #include "v8/include/v8.h" |
| 101 | 101 |
| 102 #if defined(ENABLE_WEBRTC) | 102 #if defined(ENABLE_WEBRTC) |
| 103 #include "chrome/renderer/extensions/webrtc_native_handler.h" | 103 #include "chrome/renderer/extensions/webrtc_native_handler.h" |
| 104 #endif | 104 #endif |
| 105 | 105 |
| 106 using WebKit::WebDataSource; | 106 using blink::WebDataSource; |
| 107 using WebKit::WebDocument; | 107 using blink::WebDocument; |
| 108 using WebKit::WebFrame; | 108 using blink::WebFrame; |
| 109 using WebKit::WebScopedUserGesture; | 109 using blink::WebScopedUserGesture; |
| 110 using WebKit::WebSecurityPolicy; | 110 using blink::WebSecurityPolicy; |
| 111 using WebKit::WebString; | 111 using blink::WebString; |
| 112 using WebKit::WebVector; | 112 using blink::WebVector; |
| 113 using WebKit::WebView; | 113 using blink::WebView; |
| 114 using content::RenderThread; | 114 using content::RenderThread; |
| 115 using content::RenderView; | 115 using content::RenderView; |
| 116 | 116 |
| 117 namespace extensions { | 117 namespace extensions { |
| 118 | 118 |
| 119 namespace { | 119 namespace { |
| 120 | 120 |
| 121 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 121 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
| 122 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 122 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
| 123 static const char kEventDispatchFunction[] = "dispatchEvent"; | 123 static const char kEventDispatchFunction[] = "dispatchEvent"; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 base::Unretained(this))); | 178 base::Unretained(this))); |
| 179 RouteFunction("RunWithoutUserGesture", | 179 RouteFunction("RunWithoutUserGesture", |
| 180 base::Bind(&UserGesturesNativeHandler::RunWithoutUserGesture, | 180 base::Bind(&UserGesturesNativeHandler::RunWithoutUserGesture, |
| 181 base::Unretained(this))); | 181 base::Unretained(this))); |
| 182 } | 182 } |
| 183 | 183 |
| 184 private: | 184 private: |
| 185 void IsProcessingUserGesture( | 185 void IsProcessingUserGesture( |
| 186 const v8::FunctionCallbackInfo<v8::Value>& args) { | 186 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 187 args.GetReturnValue().Set(v8::Boolean::New( | 187 args.GetReturnValue().Set(v8::Boolean::New( |
| 188 WebKit::WebUserGestureIndicator::isProcessingUserGesture())); | 188 blink::WebUserGestureIndicator::isProcessingUserGesture())); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void RunWithUserGesture( | 191 void RunWithUserGesture( |
| 192 const v8::FunctionCallbackInfo<v8::Value>& args) { | 192 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 193 WebKit::WebScopedUserGesture user_gesture; | 193 blink::WebScopedUserGesture user_gesture; |
| 194 CHECK_EQ(args.Length(), 1); | 194 CHECK_EQ(args.Length(), 1); |
| 195 CHECK(args[0]->IsFunction()); | 195 CHECK(args[0]->IsFunction()); |
| 196 v8::Handle<v8::Value> no_args; | 196 v8::Handle<v8::Value> no_args; |
| 197 context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]), | 197 context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]), |
| 198 0, &no_args); | 198 0, &no_args); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void RunWithoutUserGesture( | 201 void RunWithoutUserGesture( |
| 202 const v8::FunctionCallbackInfo<v8::Value>& args) { | 202 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 203 WebKit::WebUserGestureIndicator::consumeUserGesture(); | 203 blink::WebUserGestureIndicator::consumeUserGesture(); |
| 204 CHECK_EQ(args.Length(), 1); | 204 CHECK_EQ(args.Length(), 1); |
| 205 CHECK(args[0]->IsFunction()); | 205 CHECK(args[0]->IsFunction()); |
| 206 v8::Handle<v8::Value> no_args; | 206 v8::Handle<v8::Value> no_args; |
| 207 context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]), | 207 context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]), |
| 208 0, &no_args); | 208 0, &no_args); |
| 209 } | 209 } |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 class V8ContextNativeHandler : public ObjectBackedNativeHandler { | 212 class V8ContextNativeHandler : public ObjectBackedNativeHandler { |
| 213 public: | 213 public: |
| (...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 return; | 1252 return; |
| 1253 | 1253 |
| 1254 context->DispatchOnUnloadEvent(); | 1254 context->DispatchOnUnloadEvent(); |
| 1255 // TODO(kalman): add an invalidation observer interface to ChromeV8Context. | 1255 // TODO(kalman): add an invalidation observer interface to ChromeV8Context. |
| 1256 request_sender_->InvalidateSource(context); | 1256 request_sender_->InvalidateSource(context); |
| 1257 | 1257 |
| 1258 v8_context_set_.Remove(context); | 1258 v8_context_set_.Remove(context); |
| 1259 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 1259 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
| 1260 } | 1260 } |
| 1261 | 1261 |
| 1262 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) { | 1262 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) { |
| 1263 if (IsWithinPlatformApp()) { | 1263 if (IsWithinPlatformApp()) { |
| 1264 // WebKit doesn't let us define an additional user agent stylesheet, so we | 1264 // WebKit doesn't let us define an additional user agent stylesheet, so we |
| 1265 // insert the default platform app stylesheet into all documents that are | 1265 // insert the default platform app stylesheet into all documents that are |
| 1266 // loaded in each app. | 1266 // loaded in each app. |
| 1267 std::string stylesheet = | 1267 std::string stylesheet = |
| 1268 ResourceBundle::GetSharedInstance(). | 1268 ResourceBundle::GetSharedInstance(). |
| 1269 GetRawDataResource(IDR_PLATFORM_APP_CSS).as_string(); | 1269 GetRawDataResource(IDR_PLATFORM_APP_CSS).as_string(); |
| 1270 ReplaceFirstSubstringAfterOffset(&stylesheet, 0, | 1270 ReplaceFirstSubstringAfterOffset(&stylesheet, 0, |
| 1271 "$FONTFAMILY", system_font_family_); | 1271 "$FONTFAMILY", system_font_family_); |
| 1272 ReplaceFirstSubstringAfterOffset(&stylesheet, 0, | 1272 ReplaceFirstSubstringAfterOffset(&stylesheet, 0, |
| 1273 "$FONTSIZE", system_font_size_); | 1273 "$FONTSIZE", system_font_size_); |
| 1274 frame->document().insertUserStyleSheet( | 1274 frame->document().insertUserStyleSheet( |
| 1275 WebString::fromUTF8(stylesheet), WebDocument::UserStyleUserLevel); | 1275 WebString::fromUTF8(stylesheet), WebDocument::UserStyleUserLevel); |
| 1276 } | 1276 } |
| 1277 | 1277 |
| 1278 content_watcher_->DidCreateDocumentElement(frame); | 1278 content_watcher_->DidCreateDocumentElement(frame); |
| 1279 } | 1279 } |
| 1280 | 1280 |
| 1281 void Dispatcher::DidMatchCSS( | 1281 void Dispatcher::DidMatchCSS( |
| 1282 WebKit::WebFrame* frame, | 1282 blink::WebFrame* frame, |
| 1283 const WebKit::WebVector<WebKit::WebString>& newly_matching_selectors, | 1283 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
| 1284 const WebKit::WebVector<WebKit::WebString>& stopped_matching_selectors) { | 1284 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
| 1285 content_watcher_->DidMatchCSS( | 1285 content_watcher_->DidMatchCSS( |
| 1286 frame, newly_matching_selectors, stopped_matching_selectors); | 1286 frame, newly_matching_selectors, stopped_matching_selectors); |
| 1287 } | 1287 } |
| 1288 | 1288 |
| 1289 | 1289 |
| 1290 void Dispatcher::OnActivateExtension(const std::string& extension_id) { | 1290 void Dispatcher::OnActivateExtension(const std::string& extension_id) { |
| 1291 const Extension* extension = extensions_.GetByID(extension_id); | 1291 const Extension* extension = extensions_.GetByID(extension_id); |
| 1292 if (!extension) { | 1292 if (!extension) { |
| 1293 // Extension was activated but was never loaded. This probably means that | 1293 // Extension was activated but was never loaded. This probably means that |
| 1294 // the renderer failed to load it (or the browser failed to tell us when it | 1294 // the renderer failed to load it (or the browser failed to tell us when it |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 extension->url(), | 1356 extension->url(), |
| 1357 WebString::fromUTF8(schemes[j]), | 1357 WebString::fromUTF8(schemes[j]), |
| 1358 WebString::fromUTF8(i->host()), | 1358 WebString::fromUTF8(i->host()), |
| 1359 i->match_subdomains()); | 1359 i->match_subdomains()); |
| 1360 } | 1360 } |
| 1361 } | 1361 } |
| 1362 } | 1362 } |
| 1363 } | 1363 } |
| 1364 | 1364 |
| 1365 void Dispatcher::EnableCustomElementWhiteList() { | 1365 void Dispatcher::EnableCustomElementWhiteList() { |
| 1366 WebKit::WebRuntimeFeatures::enableEmbedderCustomElements(true); | 1366 blink::WebRuntimeFeatures::enableEmbedderCustomElements(true); |
| 1367 WebKit::WebCustomElement::addEmbedderCustomElementName("webview"); | 1367 blink::WebCustomElement::addEmbedderCustomElementName("webview"); |
| 1368 // TODO(fsamuel): Add <adview> to the whitelist once it has been converted | 1368 // TODO(fsamuel): Add <adview> to the whitelist once it has been converted |
| 1369 // into a custom element. | 1369 // into a custom element. |
| 1370 WebKit::WebCustomElement::addEmbedderCustomElementName("browser-plugin"); | 1370 blink::WebCustomElement::addEmbedderCustomElementName("browser-plugin"); |
| 1371 } | 1371 } |
| 1372 | 1372 |
| 1373 void Dispatcher::AddOrRemoveBindings(const std::string& extension_id) { | 1373 void Dispatcher::AddOrRemoveBindings(const std::string& extension_id) { |
| 1374 v8_context_set().ForEach( | 1374 v8_context_set().ForEach( |
| 1375 extension_id, | 1375 extension_id, |
| 1376 NULL, // all render views | 1376 NULL, // all render views |
| 1377 base::Bind(&Dispatcher::AddOrRemoveBindingsForContext, | 1377 base::Bind(&Dispatcher::AddOrRemoveBindingsForContext, |
| 1378 base::Unretained(this))); | 1378 base::Unretained(this))); |
| 1379 } | 1379 } |
| 1380 | 1380 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 return SandboxedPageInfo::IsSandboxedPage(extension, url.path()); | 1499 return SandboxedPageInfo::IsSandboxedPage(extension, url.path()); |
| 1500 } | 1500 } |
| 1501 } | 1501 } |
| 1502 return false; | 1502 return false; |
| 1503 } | 1503 } |
| 1504 | 1504 |
| 1505 Feature::Context Dispatcher::ClassifyJavaScriptContext( | 1505 Feature::Context Dispatcher::ClassifyJavaScriptContext( |
| 1506 const std::string& extension_id, | 1506 const std::string& extension_id, |
| 1507 int extension_group, | 1507 int extension_group, |
| 1508 const GURL& url, | 1508 const GURL& url, |
| 1509 const WebKit::WebSecurityOrigin& origin) { | 1509 const blink::WebSecurityOrigin& origin) { |
| 1510 DCHECK_GE(extension_group, 0); | 1510 DCHECK_GE(extension_group, 0); |
| 1511 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { | 1511 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { |
| 1512 return extensions_.Contains(extension_id) ? | 1512 return extensions_.Contains(extension_id) ? |
| 1513 Feature::CONTENT_SCRIPT_CONTEXT : Feature::UNSPECIFIED_CONTEXT; | 1513 Feature::CONTENT_SCRIPT_CONTEXT : Feature::UNSPECIFIED_CONTEXT; |
| 1514 } | 1514 } |
| 1515 | 1515 |
| 1516 // We have an explicit check for sandboxed pages before checking whether the | 1516 // We have an explicit check for sandboxed pages before checking whether the |
| 1517 // extension is active in this process because: | 1517 // extension is active in this process because: |
| 1518 // 1. Sandboxed pages run in the same process as regular extension pages, so | 1518 // 1. Sandboxed pages run in the same process as regular extension pages, so |
| 1519 // the extension is considered active. | 1519 // the extension is considered active. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1555 } | 1555 } |
| 1556 | 1556 |
| 1557 if (!context->extension()) { | 1557 if (!context->extension()) { |
| 1558 v8::ThrowException( | 1558 v8::ThrowException( |
| 1559 v8::Exception::Error(v8::String::New("Not in an extension."))); | 1559 v8::Exception::Error(v8::String::New("Not in an extension."))); |
| 1560 return false; | 1560 return false; |
| 1561 } | 1561 } |
| 1562 | 1562 |
| 1563 // Theoretically we could end up with bindings being injected into sandboxed | 1563 // Theoretically we could end up with bindings being injected into sandboxed |
| 1564 // frames, for example content scripts. Don't let them execute API functions. | 1564 // frames, for example content scripts. Don't let them execute API functions. |
| 1565 WebKit::WebFrame* frame = context->web_frame(); | 1565 blink::WebFrame* frame = context->web_frame(); |
| 1566 if (IsSandboxedPage(UserScriptSlave::GetDataSourceURLForFrame(frame))) { | 1566 if (IsSandboxedPage(UserScriptSlave::GetDataSourceURLForFrame(frame))) { |
| 1567 static const char kMessage[] = | 1567 static const char kMessage[] = |
| 1568 "%s cannot be used within a sandboxed frame."; | 1568 "%s cannot be used within a sandboxed frame."; |
| 1569 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1569 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1570 v8::ThrowException( | 1570 v8::ThrowException( |
| 1571 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1571 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1572 return false; | 1572 return false; |
| 1573 } | 1573 } |
| 1574 | 1574 |
| 1575 Feature::Availability availability = context->GetAvailability(function_name); | 1575 Feature::Availability availability = context->GetAvailability(function_name); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 RenderView* background_view = | 1630 RenderView* background_view = |
| 1631 ExtensionHelper::GetBackgroundPage(extension_id); | 1631 ExtensionHelper::GetBackgroundPage(extension_id); |
| 1632 if (background_view) { | 1632 if (background_view) { |
| 1633 background_view->Send(new ExtensionHostMsg_EventAck( | 1633 background_view->Send(new ExtensionHostMsg_EventAck( |
| 1634 background_view->GetRoutingID())); | 1634 background_view->GetRoutingID())); |
| 1635 } | 1635 } |
| 1636 } | 1636 } |
| 1637 } | 1637 } |
| 1638 | 1638 |
| 1639 } // namespace extensions | 1639 } // namespace extensions |
| OLD | NEW |