| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/event_bindings.h" | 5 #include "chrome/renderer/extensions/event_bindings.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/singleton.h" | 8 #include "base/singleton.h" |
| 9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| 11 #include "chrome/renderer/extensions/bindings_utils.h" | 11 #include "chrome/renderer/extensions/bindings_utils.h" |
| 12 #include "chrome/renderer/extensions/event_bindings.h" | 12 #include "chrome/renderer/extensions/event_bindings.h" |
| 13 #include "chrome/renderer/extensions/extension_process_bindings.h" | 13 #include "chrome/renderer/extensions/extension_process_bindings.h" |
| 14 #include "chrome/renderer/extensions/extension_renderer_info.h" |
| 14 #include "chrome/renderer/extensions/js_only_v8_extensions.h" | 15 #include "chrome/renderer/extensions/js_only_v8_extensions.h" |
| 15 #include "chrome/renderer/render_thread.h" | 16 #include "chrome/renderer/render_thread.h" |
| 16 #include "chrome/renderer/render_view.h" | 17 #include "chrome/renderer/render_view.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "grit/renderer_resources.h" | 19 #include "grit/renderer_resources.h" |
| 19 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" | 20 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" |
| 20 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 21 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" | 22 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
| 22 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 23 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 23 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" | 24 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 GURL(renderview->webview()->mainFrame()->url()).SchemeIs( | 161 GURL(renderview->webview()->mainFrame()->url()).SchemeIs( |
| 161 chrome::kExtensionScheme) && | 162 chrome::kExtensionScheme) && |
| 162 renderview->webview()->mainFrame()->securityOrigin().canRequest( | 163 renderview->webview()->mainFrame()->securityOrigin().canRequest( |
| 163 event_url))); | 164 event_url))); |
| 164 return url_permissions_ok; | 165 return url_permissions_ok; |
| 165 } | 166 } |
| 166 | 167 |
| 167 } // namespace | 168 } // namespace |
| 168 | 169 |
| 169 const char* EventBindings::kName = "chrome/EventBindings"; | 170 const char* EventBindings::kName = "chrome/EventBindings"; |
| 171 const char* EventBindings::kTestingExtensionId = |
| 172 "oooooooooooooooooooooooooooooooo"; |
| 170 | 173 |
| 171 v8::Extension* EventBindings::Get() { | 174 v8::Extension* EventBindings::Get() { |
| 172 static v8::Extension* extension = new ExtensionImpl(); | 175 static v8::Extension* extension = new ExtensionImpl(); |
| 173 bindings_registered = true; | 176 bindings_registered = true; |
| 174 return extension; | 177 return extension; |
| 175 } | 178 } |
| 176 | 179 |
| 177 // static | 180 // static |
| 178 void EventBindings::SetRenderThread(RenderThreadBase* thread) { | 181 void EventBindings::SetRenderThread(RenderThreadBase* thread) { |
| 179 render_thread = thread; | 182 render_thread = thread; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 v8::Local<v8::Context> context = v8::Context::GetCurrent(); | 253 v8::Local<v8::Context> context = v8::Context::GetCurrent(); |
| 251 DCHECK(!context.IsEmpty()); | 254 DCHECK(!context.IsEmpty()); |
| 252 DCHECK(bindings_utils::FindContext(context) == contexts.end()); | 255 DCHECK(bindings_utils::FindContext(context) == contexts.end()); |
| 253 | 256 |
| 254 // Figure out the frame's URL. If the frame is loading, use its provisional | 257 // Figure out the frame's URL. If the frame is loading, use its provisional |
| 255 // URL, since we get this notification before commit. | 258 // URL, since we get this notification before commit. |
| 256 WebDataSource* ds = frame->provisionalDataSource(); | 259 WebDataSource* ds = frame->provisionalDataSource(); |
| 257 if (!ds) | 260 if (!ds) |
| 258 ds = frame->dataSource(); | 261 ds = frame->dataSource(); |
| 259 GURL url = ds->request().url(); | 262 GURL url = ds->request().url(); |
| 260 std::string extension_id; | 263 std::string extension_id = ExtensionRendererInfo::GetIdByURL(url); |
| 261 if (url.SchemeIs(chrome::kExtensionScheme)) { | 264 |
| 262 extension_id = url.host(); | 265 if (!ExtensionRendererInfo::ExtensionBindingsAllowed(url) && |
| 263 } else if (!content_script) { | 266 !content_script) { |
| 264 // This context is a regular non-extension web page. Ignore it. We only | 267 // This context is a regular non-extension web page. Ignore it. We only |
| 265 // care about content scripts and extension frames. | 268 // care about content scripts and extension frames. |
| 266 // (Unless we're in unit tests, in which case we don't care what the URL | 269 // (Unless we're in unit tests, in which case we don't care what the URL |
| 267 // is). | 270 // is). |
| 268 DCHECK(frame_context.IsEmpty() || frame_context == context); | 271 DCHECK(frame_context.IsEmpty() || frame_context == context); |
| 269 if (!in_unit_tests) | 272 if (!in_unit_tests) |
| 270 return; | 273 return; |
| 274 |
| 275 // For tests, we want the dispatchOnLoad to actually setup our bindings, |
| 276 // so we give a fake extension id; |
| 277 extension_id = kTestingExtensionId; |
| 271 } | 278 } |
| 272 | 279 |
| 273 v8::Persistent<v8::Context> persistent_context = | 280 v8::Persistent<v8::Context> persistent_context = |
| 274 v8::Persistent<v8::Context>::New(context); | 281 v8::Persistent<v8::Context>::New(context); |
| 275 WebFrame* parent_frame = NULL; | 282 WebFrame* parent_frame = NULL; |
| 276 | 283 |
| 277 if (content_script) { | 284 if (content_script) { |
| 278 DCHECK(frame_context != context); | 285 DCHECK(frame_context != context); |
| 279 parent_frame = frame; | 286 parent_frame = frame; |
| 280 // Content script contexts can get GCed before their frame goes away, so | 287 // Content script contexts can get GCed before their frame goes away, so |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 // TODO(rafaelw): Consider only doing this check if function_name == | 362 // TODO(rafaelw): Consider only doing this check if function_name == |
| 356 // "Event.dispatchJSON". | 363 // "Event.dispatchJSON". |
| 357 #ifdef _DEBUG | 364 #ifdef _DEBUG |
| 358 if (!retval.IsEmpty() && !retval->IsUndefined()) { | 365 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
| 359 std::string error = *v8::String::AsciiValue(retval); | 366 std::string error = *v8::String::AsciiValue(retval); |
| 360 DCHECK(false) << error; | 367 DCHECK(false) << error; |
| 361 } | 368 } |
| 362 #endif | 369 #endif |
| 363 } | 370 } |
| 364 } | 371 } |
| OLD | NEW |