Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Unified Diff: chrome/renderer/extensions/event_bindings.cc

Issue 3263007: Reland r57788 - Expose Extension Bindings to Component Applications (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: don't hide gallery url in omnibar Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/extensions/event_bindings.cc
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc
index 52f5d0e1c6e0f22516fda0d7a911c5359bb8eb62..1de179e1a5164a63484cd97b251c3cb0791f51c8 100644
--- a/chrome/renderer/extensions/event_bindings.cc
+++ b/chrome/renderer/extensions/event_bindings.cc
@@ -11,6 +11,7 @@
#include "chrome/renderer/extensions/bindings_utils.h"
#include "chrome/renderer/extensions/event_bindings.h"
#include "chrome/renderer/extensions/extension_process_bindings.h"
+#include "chrome/renderer/extensions/extension_renderer_info.h"
#include "chrome/renderer/extensions/js_only_v8_extensions.h"
#include "chrome/renderer/render_thread.h"
#include "chrome/renderer/render_view.h"
@@ -167,6 +168,8 @@ static bool HasSufficientPermissions(ContextInfo* context,
} // namespace
const char* EventBindings::kName = "chrome/EventBindings";
+const char* EventBindings::kTestingExtensionId =
+ "oooooooooooooooooooooooooooooooo";
v8::Extension* EventBindings::Get() {
static v8::Extension* extension = new ExtensionImpl();
@@ -257,10 +260,18 @@ void EventBindings::HandleContextCreated(WebFrame* frame, bool content_script) {
if (!ds)
ds = frame->dataSource();
GURL url = ds->request().url();
- std::string extension_id;
- if (url.SchemeIs(chrome::kExtensionScheme)) {
- extension_id = url.host();
- } else if (!content_script) {
+ std::string extension_id = ExtensionRendererInfo::GetIdByURL(url);
+
+ // Note: because process isolation doesn't work correcly with redirects,
+ // it is possible that a page that IS in an extension process won't have
+ // bindings setup for it, so we must also check IsExtensionProcess, otherwise
+ // we'll attempt to invoke a JS function that doesn't exist.
+ // Fixing crbug.com/53610 should fix this as well.
+ RenderThread* current_thread = RenderThread::current();
+ if ((!current_thread ||
+ !current_thread->IsExtensionProcess() ||
+ !ExtensionRendererInfo::ExtensionBindingsAllowed(url)) &&
+ !content_script) {
// This context is a regular non-extension web page. Ignore it. We only
// care about content scripts and extension frames.
// (Unless we're in unit tests, in which case we don't care what the URL
@@ -268,6 +279,10 @@ void EventBindings::HandleContextCreated(WebFrame* frame, bool content_script) {
DCHECK(frame_context.IsEmpty() || frame_context == context);
if (!in_unit_tests)
return;
+
+ // For tests, we want the dispatchOnLoad to actually setup our bindings,
+ // so we give a fake extension id;
+ extension_id = kTestingExtensionId;
}
v8::Persistent<v8::Context> persistent_context =
« no previous file with comments | « chrome/renderer/extensions/event_bindings.h ('k') | chrome/renderer/extensions/extension_process_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698