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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "content/public/common/url_utils.h" |
12 #include "content/renderer/web_frame_utils.h" | 13 #include "content/renderer/web_frame_utils.h" |
13 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
14 #include "third_party/WebKit/public/platform/WebVector.h" | 15 #include "third_party/WebKit/public/platform/WebVector.h" |
15 #include "third_party/WebKit/public/web/WebDocument.h" | 16 #include "third_party/WebKit/public/web/WebDocument.h" |
16 #include "third_party/WebKit/public/web/WebElement.h" | 17 #include "third_party/WebKit/public/web/WebElement.h" |
17 #include "third_party/WebKit/public/web/WebElementCollection.h" | 18 #include "third_party/WebKit/public/web/WebElementCollection.h" |
18 #include "third_party/WebKit/public/web/WebInputElement.h" | 19 #include "third_party/WebKit/public/web/WebInputElement.h" |
19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 20 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
20 #include "third_party/WebKit/public/web/WebNode.h" | 21 #include "third_party/WebKit/public/web/WebNode.h" |
21 #include "third_party/WebKit/public/web/WebView.h" | 22 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (!element_url.SchemeIsHTTPOrHTTPS() && | 90 if (!element_url.SchemeIsHTTPOrHTTPS() && |
90 !element_url.SchemeIs(url::kFileScheme)) | 91 !element_url.SchemeIs(url::kFileScheme)) |
91 return; | 92 return; |
92 | 93 |
93 result->resources_list->push_back(element_url); | 94 result->resources_list->push_back(element_url); |
94 } | 95 } |
95 | 96 |
96 } // namespace | 97 } // namespace |
97 | 98 |
98 bool GetSavableResourceLinksForFrame(WebFrame* current_frame, | 99 bool GetSavableResourceLinksForFrame(WebFrame* current_frame, |
99 SavableResourcesResult* result, | 100 SavableResourcesResult* result) { |
100 const char** savable_schemes) { | |
101 // Get current frame's URL. | 101 // Get current frame's URL. |
102 GURL current_frame_url = current_frame->document().url(); | 102 GURL current_frame_url = current_frame->document().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 bool is_valid_protocol = false; | 109 if (!IsSavableURL(current_frame_url)) |
110 for (int i = 0; savable_schemes[i] != NULL; ++i) { | |
111 if (current_frame_url.SchemeIs(savable_schemes[i])) { | |
112 is_valid_protocol = true; | |
113 break; | |
114 } | |
115 } | |
116 if (!is_valid_protocol) | |
117 return false; | 110 return false; |
118 | 111 |
119 // Get current using document. | 112 // Get current using document. |
120 WebDocument current_doc = current_frame->document(); | 113 WebDocument current_doc = current_frame->document(); |
121 // Go through all descent nodes. | 114 // Go through all descent nodes. |
122 WebElementCollection all = current_doc.all(); | 115 WebElementCollection all = current_doc.all(); |
123 // Go through all elements in this frame. | 116 // Go through all elements in this frame. |
124 for (WebElement element = all.firstItem(); !element.isNull(); | 117 for (WebElement element = all.firstItem(); !element.isNull(); |
125 element = all.nextItem()) { | 118 element = all.nextItem()) { |
126 GetSavableResourceLinkForElement(element, | 119 GetSavableResourceLinkForElement(element, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // otherwise return NULL. | 167 // otherwise return NULL. |
175 if (!value.isNull() && !value.isEmpty() && | 168 if (!value.isNull() && !value.isEmpty() && |
176 !base::StartsWith(value.utf8(), "javascript:", | 169 !base::StartsWith(value.utf8(), "javascript:", |
177 base::CompareCase::INSENSITIVE_ASCII)) | 170 base::CompareCase::INSENSITIVE_ASCII)) |
178 return value; | 171 return value; |
179 | 172 |
180 return WebString(); | 173 return WebString(); |
181 } | 174 } |
182 | 175 |
183 } // namespace content | 176 } // namespace content |
OLD | NEW |