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/values.h" | 10 #include "base/values.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 return GURL(data_source->request().url()); | 165 return GURL(data_source->request().url()); |
166 } | 166 } |
167 | 167 |
168 // static | 168 // static |
169 GURL ScriptContext::GetEffectiveDocumentURL(const blink::WebFrame* frame, | 169 GURL ScriptContext::GetEffectiveDocumentURL(const blink::WebFrame* frame, |
170 const GURL& document_url, | 170 const GURL& document_url, |
171 bool match_about_blank) { | 171 bool match_about_blank) { |
172 // Common scenario. If |match_about_blank| is false (as is the case in most | 172 // Common scenario. If |match_about_blank| is false (as is the case in most |
173 // extensions), or if the frame is not an about:-page, just return | 173 // extensions), or if the frame is not an about:-page, just return |
174 // |document_url| (supposedly the URL of the frame). | 174 // |document_url| (supposedly the URL of the frame). |
175 if (!match_about_blank || !document_url.SchemeIs(content::kAboutScheme)) | 175 if (!match_about_blank || !document_url.SchemeIs(url::kAboutScheme)) |
176 return document_url; | 176 return document_url; |
177 | 177 |
178 // Non-sandboxed about:blank and about:srcdoc pages inherit their security | 178 // Non-sandboxed about:blank and about:srcdoc pages inherit their security |
179 // origin from their parent frame/window. So, traverse the frame/window | 179 // origin from their parent frame/window. So, traverse the frame/window |
180 // hierarchy to find the closest non-about:-page and return its URL. | 180 // hierarchy to find the closest non-about:-page and return its URL. |
181 const blink::WebFrame* parent = frame; | 181 const blink::WebFrame* parent = frame; |
182 do { | 182 do { |
183 parent = parent->parent() ? parent->parent() : parent->opener(); | 183 parent = parent->parent() ? parent->parent() : parent->opener(); |
184 } while (parent != NULL && | 184 } while (parent != NULL && |
185 GURL(parent->document().url()).SchemeIs(content::kAboutScheme)); | 185 GURL(parent->document().url()).SchemeIs(url::kAboutScheme)); |
186 | 186 |
187 if (parent) { | 187 if (parent) { |
188 // Only return the parent URL if the frame can access it. | 188 // Only return the parent URL if the frame can access it. |
189 const blink::WebDocument& parent_document = parent->document(); | 189 const blink::WebDocument& parent_document = parent->document(); |
190 if (frame->document().securityOrigin().canAccess( | 190 if (frame->document().securityOrigin().canAccess( |
191 parent_document.securityOrigin())) | 191 parent_document.securityOrigin())) |
192 return parent_document.url(); | 192 return parent_document.url(); |
193 } | 193 } |
194 return document_url; | 194 return document_url; |
195 } | 195 } |
(...skipping 18 matching lines...) Expand all Loading... |
214 v8::Handle<v8::Value> retval = module_system()->CallModuleMethod( | 214 v8::Handle<v8::Value> retval = module_system()->CallModuleMethod( |
215 "sendRequest", "handleResponse", arraysize(argv), argv); | 215 "sendRequest", "handleResponse", arraysize(argv), argv); |
216 | 216 |
217 // In debug, the js will validate the callback parameters and return a | 217 // In debug, the js will validate the callback parameters and return a |
218 // string if a validation error has occured. | 218 // string if a validation error has occured. |
219 DCHECK(retval.IsEmpty() || retval->IsUndefined()) | 219 DCHECK(retval.IsEmpty() || retval->IsUndefined()) |
220 << *v8::String::Utf8Value(retval); | 220 << *v8::String::Utf8Value(retval); |
221 } | 221 } |
222 | 222 |
223 } // namespace extensions | 223 } // namespace extensions |
OLD | NEW |