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

Unified Diff: Source/bindings/core/v8/BindingSecurity.cpp

Issue 1085973003: Make error messages for cross-domain access OOPIF-friendly. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase (pull in CL to print errors on calling window) Created 5 years, 8 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
« no previous file with comments | « no previous file | Source/core/frame/DOMWindow.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/BindingSecurity.cpp
diff --git a/Source/bindings/core/v8/BindingSecurity.cpp b/Source/bindings/core/v8/BindingSecurity.cpp
index 3f9c7eeae381754d04ed17c45ca0fd4befb6945d..6cf718f525d152abe43584f5d8645001c4fc288e 100644
--- a/Source/bindings/core/v8/BindingSecurity.cpp
+++ b/Source/bindings/core/v8/BindingSecurity.cpp
@@ -41,60 +41,50 @@
namespace blink {
-static bool isDocumentAccessibleFromDOMWindow(Document* targetDocument, LocalDOMWindow* callingWindow)
+static bool isOriginAccessibleFromDOMWindow(SecurityOrigin* targetOrigin, LocalDOMWindow* callingWindow)
{
- if (!targetDocument)
- return false;
-
- if (!callingWindow)
- return false;
-
- if (callingWindow->document()->securityOrigin()->canAccess(targetDocument->securityOrigin()))
- return true;
-
- return false;
+ return callingWindow && callingWindow->document()->securityOrigin()->canAccess(targetOrigin);
}
-static bool canAccessDocument(v8::Isolate* isolate, Document* targetDocument, ExceptionState& exceptionState)
+static bool canAccessFrame(v8::Isolate* isolate, SecurityOrigin* targetFrameOrigin, DOMWindow* targetWindow, ExceptionState& exceptionState)
{
LocalDOMWindow* callingWindow = callingDOMWindow(isolate);
- if (isDocumentAccessibleFromDOMWindow(targetDocument, callingWindow))
+ if (isOriginAccessibleFromDOMWindow(targetFrameOrigin, callingWindow))
return true;
- if (targetDocument->domWindow())
- exceptionState.throwSecurityError(targetDocument->domWindow()->sanitizedCrossDomainAccessErrorMessage(callingWindow), targetDocument->domWindow()->crossDomainAccessErrorMessage(callingWindow));
+ if (targetWindow)
+ exceptionState.throwSecurityError(targetWindow->sanitizedCrossDomainAccessErrorMessage(callingWindow), targetWindow->crossDomainAccessErrorMessage(callingWindow));
return false;
}
-static bool canAccessDocument(v8::Isolate* isolate, Document* targetDocument, SecurityReportingOption reportingOption = ReportSecurityError)
+static bool canAccessFrame(v8::Isolate* isolate, SecurityOrigin* targetFrameOrigin, DOMWindow* targetWindow, SecurityReportingOption reportingOption = ReportSecurityError)
{
LocalDOMWindow* callingWindow = callingDOMWindow(isolate);
- if (isDocumentAccessibleFromDOMWindow(targetDocument, callingWindow))
+ if (isOriginAccessibleFromDOMWindow(targetFrameOrigin, callingWindow))
return true;
- if (reportingOption == ReportSecurityError && targetDocument->domWindow())
- callingWindow->printErrorMessage(targetDocument->domWindow()->crossDomainAccessErrorMessage(callingWindow));
-
+ if (reportingOption == ReportSecurityError && targetWindow)
+ callingWindow->printErrorMessage(targetWindow->crossDomainAccessErrorMessage(callingWindow));
return false;
}
bool BindingSecurity::shouldAllowAccessToFrame(v8::Isolate* isolate, Frame* target, SecurityReportingOption reportingOption)
{
- if (!target || !target->isLocalFrame())
+ if (!target || !target->securityContext())
return false;
- return canAccessDocument(isolate, toLocalFrame(target)->document(), reportingOption);
+ return canAccessFrame(isolate, target->securityContext()->securityOrigin(), target->domWindow(), reportingOption);
}
bool BindingSecurity::shouldAllowAccessToFrame(v8::Isolate* isolate, Frame* target, ExceptionState& exceptionState)
{
- if (!target || !target->isLocalFrame())
+ if (!target || !target->securityContext())
return false;
- return canAccessDocument(isolate, toLocalFrame(target)->document(), exceptionState);
+ return canAccessFrame(isolate, target->securityContext()->securityOrigin(), target->domWindow(), exceptionState);
}
bool BindingSecurity::shouldAllowAccessToNode(v8::Isolate* isolate, Node* target, ExceptionState& exceptionState)
{
- return target && canAccessDocument(isolate, &target->document(), exceptionState);
+ return target && canAccessFrame(isolate, target->document().securityOrigin(), target->document().domWindow(), exceptionState);
dcheng 2015/04/23 17:39:57 Would it make sense to have canAccessFrame() take
alexmos 2015/04/23 17:45:28 That was the first thing I tried, and unfortunatel
dcheng 2015/04/23 18:01:24 Do we actually return a true value in that case? O
alexmos 2015/04/23 21:25:23 That particular test returns false - I think it ha
}
}
« no previous file with comments | « no previous file | Source/core/frame/DOMWindow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698