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

Side by Side 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, 3 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 unified diff | Download patch
OLDNEW
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
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
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 // Note: because process isolation doesn't work correcly with redirects,
263 } else if (!content_script) { 266 // it is possible that a page that IS in an extension process won't have
267 // bindings setup for it, so we must also check IsExtensionProcess, otherwise
268 // we'll attempt to invoke a JS function that doesn't exist.
269 // Fixing crbug.com/53610 should fix this as well.
270 RenderThread* current_thread = RenderThread::current();
271 if ((!current_thread ||
272 !current_thread->IsExtensionProcess() ||
273 !ExtensionRendererInfo::ExtensionBindingsAllowed(url)) &&
274 !content_script) {
264 // This context is a regular non-extension web page. Ignore it. We only 275 // This context is a regular non-extension web page. Ignore it. We only
265 // care about content scripts and extension frames. 276 // care about content scripts and extension frames.
266 // (Unless we're in unit tests, in which case we don't care what the URL 277 // (Unless we're in unit tests, in which case we don't care what the URL
267 // is). 278 // is).
268 DCHECK(frame_context.IsEmpty() || frame_context == context); 279 DCHECK(frame_context.IsEmpty() || frame_context == context);
269 if (!in_unit_tests) 280 if (!in_unit_tests)
270 return; 281 return;
282
283 // For tests, we want the dispatchOnLoad to actually setup our bindings,
284 // so we give a fake extension id;
285 extension_id = kTestingExtensionId;
271 } 286 }
272 287
273 v8::Persistent<v8::Context> persistent_context = 288 v8::Persistent<v8::Context> persistent_context =
274 v8::Persistent<v8::Context>::New(context); 289 v8::Persistent<v8::Context>::New(context);
275 WebFrame* parent_frame = NULL; 290 WebFrame* parent_frame = NULL;
276 291
277 if (content_script) { 292 if (content_script) {
278 DCHECK(frame_context != context); 293 DCHECK(frame_context != context);
279 parent_frame = frame; 294 parent_frame = frame;
280 // Content script contexts can get GCed before their frame goes away, so 295 // Content script contexts can get GCed before their frame goes away, so
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 // TODO(rafaelw): Consider only doing this check if function_name == 370 // TODO(rafaelw): Consider only doing this check if function_name ==
356 // "Event.dispatchJSON". 371 // "Event.dispatchJSON".
357 #ifdef _DEBUG 372 #ifdef _DEBUG
358 if (!retval.IsEmpty() && !retval->IsUndefined()) { 373 if (!retval.IsEmpty() && !retval->IsUndefined()) {
359 std::string error = *v8::String::AsciiValue(retval); 374 std::string error = *v8::String::AsciiValue(retval);
360 DCHECK(false) << error; 375 DCHECK(false) << error;
361 } 376 }
362 #endif 377 #endif
363 } 378 }
364 } 379 }
OLDNEW
« 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