| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/renderer/savable_resources.h" | 5 #include "content/renderer/savable_resources.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 using blink::WebNode; | 30 using blink::WebNode; |
| 31 using blink::WebString; | 31 using blink::WebString; |
| 32 using blink::WebVector; | 32 using blink::WebVector; |
| 33 using blink::WebView; | 33 using blink::WebView; |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // Returns |true| if |web_frame| contains (or should be assumed to contain) | 38 // Returns |true| if |web_frame| contains (or should be assumed to contain) |
| 39 // a html document. | 39 // a html document. |
| 40 bool DoesFrameContainHtmlDocument(const WebFrame& web_frame, | 40 bool DoesFrameContainHtmlDocument(WebFrame* web_frame, |
| 41 const WebElement& element) { | 41 const WebElement& element) { |
| 42 if (web_frame.IsWebLocalFrame()) { | 42 if (web_frame->IsWebLocalFrame()) { |
| 43 WebDocument doc = web_frame.GetDocument(); | 43 WebDocument doc = web_frame->ToWebLocalFrame()->GetDocument(); |
| 44 return doc.IsHTMLDocument() || doc.IsXHTMLDocument(); | 44 return doc.IsHTMLDocument() || doc.IsXHTMLDocument(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Cannot inspect contents of a remote frame, so we use a heuristic: | 47 // Cannot inspect contents of a remote frame, so we use a heuristic: |
| 48 // Assume that <iframe> and <frame> elements contain a html document, | 48 // Assume that <iframe> and <frame> elements contain a html document, |
| 49 // and other elements (i.e. <object>) contain plugins or other resources. | 49 // and other elements (i.e. <object>) contain plugins or other resources. |
| 50 // If the heuristic is wrong (i.e. the remote frame in <object> does | 50 // If the heuristic is wrong (i.e. the remote frame in <object> does |
| 51 // contain an html document), then things will still work, but with the | 51 // contain an html document), then things will still work, but with the |
| 52 // following caveats: 1) original frame content will be saved and 2) links | 52 // following caveats: 1) original frame content will be saved and 2) links |
| 53 // in frame's html doc will not be rewritten to point to locally saved | 53 // in frame's html doc will not be rewritten to point to locally saved |
| 54 // files. | 54 // files. |
| 55 return element.HasHTMLTagName("iframe") || element.HasHTMLTagName("frame"); | 55 return element.HasHTMLTagName("iframe") || element.HasHTMLTagName("frame"); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // If present and valid, then push the link associated with |element| | 58 // If present and valid, then push the link associated with |element| |
| 59 // into either SavableResourcesResult::subframes or | 59 // into either SavableResourcesResult::subframes or |
| 60 // SavableResourcesResult::resources_list. | 60 // SavableResourcesResult::resources_list. |
| 61 void GetSavableResourceLinkForElement( | 61 void GetSavableResourceLinkForElement( |
| 62 const WebElement& element, | 62 const WebElement& element, |
| 63 const WebDocument& current_doc, | 63 const WebDocument& current_doc, |
| 64 SavableResourcesResult* result) { | 64 SavableResourcesResult* result) { |
| 65 // Get absolute URL. | 65 // Get absolute URL. |
| 66 WebString link_attribute_value = GetSubResourceLinkFromElement(element); | 66 WebString link_attribute_value = GetSubResourceLinkFromElement(element); |
| 67 GURL element_url = current_doc.CompleteURL(link_attribute_value); | 67 GURL element_url = current_doc.CompleteURL(link_attribute_value); |
| 68 | 68 |
| 69 // See whether to report this element as a subframe. | 69 // See whether to report this element as a subframe. |
| 70 WebFrame* web_frame = WebFrame::FromFrameOwnerElement(element); | 70 WebFrame* web_frame = WebFrame::FromFrameOwnerElement(element); |
| 71 if (web_frame && DoesFrameContainHtmlDocument(*web_frame, element)) { | 71 if (web_frame && DoesFrameContainHtmlDocument(web_frame, element)) { |
| 72 SavableSubframe subframe; | 72 SavableSubframe subframe; |
| 73 subframe.original_url = element_url; | 73 subframe.original_url = element_url; |
| 74 subframe.routing_id = RenderFrame::GetRoutingIdForWebFrame(web_frame); | 74 subframe.routing_id = RenderFrame::GetRoutingIdForWebFrame(web_frame); |
| 75 result->subframes->push_back(subframe); | 75 result->subframes->push_back(subframe); |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Check whether the node has sub resource URL or not. | 79 // Check whether the node has sub resource URL or not. |
| 80 if (link_attribute_value.IsNull()) | 80 if (link_attribute_value.IsNull()) |
| 81 return; | 81 return; |
| 82 | 82 |
| 83 // Ignore invalid URL. | 83 // Ignore invalid URL. |
| 84 if (!element_url.is_valid()) | 84 if (!element_url.is_valid()) |
| 85 return; | 85 return; |
| 86 | 86 |
| 87 // Ignore those URLs which are not standard protocols. Because FTP | 87 // Ignore those URLs which are not standard protocols. Because FTP |
| 88 // protocol does no have cache mechanism, we will skip all | 88 // protocol does no have cache mechanism, we will skip all |
| 89 // sub-resources if they use FTP protocol. | 89 // sub-resources if they use FTP protocol. |
| 90 if (!element_url.SchemeIsHTTPOrHTTPS() && | 90 if (!element_url.SchemeIsHTTPOrHTTPS() && |
| 91 !element_url.SchemeIs(url::kFileScheme)) | 91 !element_url.SchemeIs(url::kFileScheme)) |
| 92 return; | 92 return; |
| 93 | 93 |
| 94 result->resources_list->push_back(element_url); | 94 result->resources_list->push_back(element_url); |
| 95 } | 95 } |
| 96 | 96 |
| 97 } // namespace | 97 } // namespace |
| 98 | 98 |
| 99 bool GetSavableResourceLinksForFrame(WebFrame* current_frame, | 99 bool GetSavableResourceLinksForFrame(WebLocalFrame* current_frame, |
| 100 SavableResourcesResult* result) { | 100 SavableResourcesResult* result) { |
| 101 // Get current frame's URL. | 101 // Get current frame's URL. |
| 102 GURL current_frame_url = current_frame->GetDocument().Url(); | 102 GURL current_frame_url = current_frame->GetDocument().Url(); |
| 103 | 103 |
| 104 // If url of current frame is invalid, ignore it. | 104 // If url of current frame is invalid, ignore it. |
| 105 if (!current_frame_url.is_valid()) | 105 if (!current_frame_url.is_valid()) |
| 106 return false; | 106 return false; |
| 107 | 107 |
| 108 // If url of current frame is not a savable protocol, ignore it. | 108 // If url of current frame is not a savable protocol, ignore it. |
| 109 if (!IsSavableURL(current_frame_url)) | 109 if (!IsSavableURL(current_frame_url)) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // otherwise return NULL. | 165 // otherwise return NULL. |
| 166 if (!value.IsNull() && !value.IsEmpty() && | 166 if (!value.IsNull() && !value.IsEmpty() && |
| 167 !base::StartsWith(value.Utf8(), | 167 !base::StartsWith(value.Utf8(), |
| 168 "javascript:", base::CompareCase::INSENSITIVE_ASCII)) | 168 "javascript:", base::CompareCase::INSENSITIVE_ASCII)) |
| 169 return value; | 169 return value; |
| 170 | 170 |
| 171 return WebString(); | 171 return WebString(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace content | 174 } // namespace content |
| OLD | NEW |