OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/script_context.h" | 5 #include "extensions/renderer/script_context.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // |document_url| (supposedly the URL of the frame). | 182 // |document_url| (supposedly the URL of the frame). |
183 if (!match_about_blank || !document_url.SchemeIs(url::kAboutScheme)) | 183 if (!match_about_blank || !document_url.SchemeIs(url::kAboutScheme)) |
184 return document_url; | 184 return document_url; |
185 | 185 |
186 // Non-sandboxed about:blank and about:srcdoc pages inherit their security | 186 // Non-sandboxed about:blank and about:srcdoc pages inherit their security |
187 // origin from their parent frame/window. So, traverse the frame/window | 187 // origin from their parent frame/window. So, traverse the frame/window |
188 // hierarchy to find the closest non-about:-page and return its URL. | 188 // hierarchy to find the closest non-about:-page and return its URL. |
189 const blink::WebFrame* parent = frame; | 189 const blink::WebFrame* parent = frame; |
190 do { | 190 do { |
191 parent = parent->parent() ? parent->parent() : parent->opener(); | 191 parent = parent->parent() ? parent->parent() : parent->opener(); |
192 } while (parent != NULL && | 192 } while (parent != NULL && !parent->document().isNull() && |
193 GURL(parent->document().url()).SchemeIs(url::kAboutScheme)); | 193 GURL(parent->document().url()).SchemeIs(url::kAboutScheme)); |
194 | 194 |
195 if (parent) { | 195 if (parent && !parent->document().isNull()) { |
196 // Only return the parent URL if the frame can access it. | 196 // Only return the parent URL if the frame can access it. |
197 const blink::WebDocument& parent_document = parent->document(); | 197 const blink::WebDocument& parent_document = parent->document(); |
198 if (frame->document().securityOrigin().canAccess( | 198 if (frame->document().securityOrigin().canAccess( |
199 parent_document.securityOrigin())) | 199 parent_document.securityOrigin())) |
200 return parent_document.url(); | 200 return parent_document.url(); |
201 } | 201 } |
202 return document_url; | 202 return document_url; |
203 } | 203 } |
204 | 204 |
205 ScriptContext* ScriptContext::GetContext() { return this; } | 205 ScriptContext* ScriptContext::GetContext() { return this; } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 v8::Handle<v8::Value> argv[]) { | 239 v8::Handle<v8::Value> argv[]) { |
240 return CallFunction(function, argc, argv); | 240 return CallFunction(function, argc, argv); |
241 } | 241 } |
242 | 242 |
243 gin::ContextHolder* ScriptContext::GetContextHolder() { | 243 gin::ContextHolder* ScriptContext::GetContextHolder() { |
244 v8::HandleScope handle_scope(isolate()); | 244 v8::HandleScope handle_scope(isolate()); |
245 return gin::PerContextData::From(v8_context())->context_holder(); | 245 return gin::PerContextData::From(v8_context())->context_holder(); |
246 } | 246 } |
247 | 247 |
248 } // namespace extensions | 248 } // namespace extensions |
OLD | NEW |