| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/dom_operations.h" | 5 #include "webkit/glue/dom_operations.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/string_number_conversions.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_split.h" | |
| 12 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebAnimationController.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebAnimationController.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
| 15 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
| 18 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
| 19 #include "third_party/WebKit/WebKit/chromium/public/WebNodeCollection.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebNodeCollection.h" |
| 20 #include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h" | 19 #include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h" |
| 21 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 20 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 for (std::set<GURL>::iterator it = frames_set.begin(); | 231 for (std::set<GURL>::iterator it = frames_set.begin(); |
| 233 it != frames_set.end(); ++it) { | 232 it != frames_set.end(); ++it) { |
| 234 // Append unique frame source to savable frame list. | 233 // Append unique frame source to savable frame list. |
| 235 if (resources_set.find(*it) == resources_set.end()) | 234 if (resources_set.find(*it) == resources_set.end()) |
| 236 result->frames_list->push_back(*it); | 235 result->frames_list->push_back(*it); |
| 237 } | 236 } |
| 238 | 237 |
| 239 return true; | 238 return true; |
| 240 } | 239 } |
| 241 | 240 |
| 242 // Sizes a single size (the width or height) from a 'sizes' attribute. A size | |
| 243 // matches must match the following regex: [1-9][0-9]*. | |
| 244 static int ParseSingleIconSize(const string16& text) { | |
| 245 // Size must not start with 0, and be between 0 and 9. | |
| 246 if (text.empty() || !(text[0] >= L'1' && text[0] <= L'9')) | |
| 247 return 0; | |
| 248 // Make sure all chars are from 0-9. | |
| 249 for (size_t i = 1; i < text.length(); ++i) { | |
| 250 if (!(text[i] >= L'0' && text[i] <= L'9')) | |
| 251 return 0; | |
| 252 } | |
| 253 int output; | |
| 254 if (!base::StringToInt(text, &output)) | |
| 255 return 0; | |
| 256 return output; | |
| 257 } | |
| 258 | |
| 259 // Parses an icon size. An icon size must match the following regex: | |
| 260 // [1-9][0-9]*x[1-9][0-9]*. | |
| 261 // If the input couldn't be parsed, a size with a width/height < 0 is returned. | |
| 262 static gfx::Size ParseIconSize(const string16& text) { | |
| 263 std::vector<string16> sizes; | |
| 264 base::SplitStringDontTrim(text, L'x', &sizes); | |
| 265 if (sizes.size() != 2) | |
| 266 return gfx::Size(); | |
| 267 | |
| 268 return gfx::Size(ParseSingleIconSize(sizes[0]), | |
| 269 ParseSingleIconSize(sizes[1])); | |
| 270 } | |
| 271 | |
| 272 WebApplicationInfo::WebApplicationInfo() {} | |
| 273 | |
| 274 WebApplicationInfo::~WebApplicationInfo() {} | |
| 275 | |
| 276 bool ParseIconSizes(const string16& text, | |
| 277 std::vector<gfx::Size>* sizes, | |
| 278 bool* is_any) { | |
| 279 *is_any = false; | |
| 280 std::vector<string16> size_strings; | |
| 281 SplitStringAlongWhitespace(text, &size_strings); | |
| 282 for (size_t i = 0; i < size_strings.size(); ++i) { | |
| 283 if (EqualsASCII(size_strings[i], "any")) { | |
| 284 *is_any = true; | |
| 285 } else { | |
| 286 gfx::Size size = ParseIconSize(size_strings[i]); | |
| 287 if (size.width() <= 0 || size.height() <= 0) | |
| 288 return false; // Bogus size. | |
| 289 sizes->push_back(size); | |
| 290 } | |
| 291 } | |
| 292 if (*is_any && !sizes->empty()) { | |
| 293 // If is_any is true, it must occur by itself. | |
| 294 return false; | |
| 295 } | |
| 296 return (*is_any || !sizes->empty()); | |
| 297 } | |
| 298 | |
| 299 static void AddInstallIcon(const WebElement& link, | |
| 300 std::vector<WebApplicationInfo::IconInfo>* icons) { | |
| 301 WebString href = link.getAttribute("href"); | |
| 302 if (href.isNull() || href.isEmpty()) | |
| 303 return; | |
| 304 | |
| 305 // Get complete url. | |
| 306 GURL url = link.document().completeURL(href); | |
| 307 if (!url.is_valid()) | |
| 308 return; | |
| 309 | |
| 310 if (!link.hasAttribute("sizes")) | |
| 311 return; | |
| 312 | |
| 313 bool is_any = false; | |
| 314 std::vector<gfx::Size> icon_sizes; | |
| 315 if (!ParseIconSizes(link.getAttribute("sizes"), &icon_sizes, &is_any) || | |
| 316 is_any || | |
| 317 icon_sizes.size() != 1) { | |
| 318 return; | |
| 319 } | |
| 320 WebApplicationInfo::IconInfo icon_info; | |
| 321 icon_info.width = icon_sizes[0].width(); | |
| 322 icon_info.height = icon_sizes[0].height(); | |
| 323 icon_info.url = url; | |
| 324 icons->push_back(icon_info); | |
| 325 } | |
| 326 | |
| 327 void GetApplicationInfo(WebView* view, WebApplicationInfo* app_info) { | |
| 328 WebFrame* main_frame = view->mainFrame(); | |
| 329 if (!main_frame) | |
| 330 return; | |
| 331 | |
| 332 WebDocument doc = main_frame->document(); | |
| 333 if (doc.isNull()) | |
| 334 return; | |
| 335 | |
| 336 WebElement head = main_frame->document().head(); | |
| 337 if (head.isNull()) | |
| 338 return; | |
| 339 | |
| 340 WebNodeList children = head.childNodes(); | |
| 341 for (unsigned i = 0; i < children.length(); ++i) { | |
| 342 WebNode child = children.item(i); | |
| 343 if (!child.isElementNode()) | |
| 344 continue; | |
| 345 WebElement elem = child.to<WebElement>(); | |
| 346 | |
| 347 if (elem.hasTagName("link")) { | |
| 348 std::string rel = elem.getAttribute("rel").utf8(); | |
| 349 // "rel" attribute may use either "icon" or "shortcut icon". | |
| 350 // see also | |
| 351 // <http://en.wikipedia.org/wiki/Favicon> | |
| 352 // <http://dev.w3.org/html5/spec/Overview.html#rel-icon> | |
| 353 if (LowerCaseEqualsASCII(rel, "icon") || | |
| 354 LowerCaseEqualsASCII(rel, "shortcut icon")) | |
| 355 AddInstallIcon(elem, &app_info->icons); | |
| 356 } else if (elem.hasTagName("meta") && elem.hasAttribute("name")) { | |
| 357 std::string name = elem.getAttribute("name").utf8(); | |
| 358 WebString content = elem.getAttribute("content"); | |
| 359 if (name == "application-name") { | |
| 360 app_info->title = content; | |
| 361 } else if (name == "description") { | |
| 362 app_info->description = content; | |
| 363 } else if (name == "application-url") { | |
| 364 std::string url = content.utf8(); | |
| 365 GURL main_url = main_frame->url(); | |
| 366 app_info->app_url = main_url.is_valid() ? | |
| 367 main_url.Resolve(url) : GURL(url); | |
| 368 if (!app_info->app_url.is_valid()) | |
| 369 app_info->app_url = GURL(); | |
| 370 } | |
| 371 } | |
| 372 } | |
| 373 } | |
| 374 | |
| 375 bool PauseAnimationAtTimeOnElementWithId(WebView* view, | 241 bool PauseAnimationAtTimeOnElementWithId(WebView* view, |
| 376 const std::string& animation_name, | 242 const std::string& animation_name, |
| 377 double time, | 243 double time, |
| 378 const std::string& element_id) { | 244 const std::string& element_id) { |
| 379 WebFrame* web_frame = view->mainFrame(); | 245 WebFrame* web_frame = view->mainFrame(); |
| 380 if (!web_frame) | 246 if (!web_frame) |
| 381 return false; | 247 return false; |
| 382 | 248 |
| 383 WebAnimationController* controller = web_frame->animationController(); | 249 WebAnimationController* controller = web_frame->animationController(); |
| 384 if (!controller) | 250 if (!controller) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 if (!element.hasTagName("meta")) | 327 if (!element.hasTagName("meta")) |
| 462 continue; | 328 continue; |
| 463 WebString value = element.getAttribute(attribute_name); | 329 WebString value = element.getAttribute(attribute_name); |
| 464 if (value.isNull() || value != attribute_value) | 330 if (value.isNull() || value != attribute_value) |
| 465 continue; | 331 continue; |
| 466 meta_elements->push_back(element); | 332 meta_elements->push_back(element); |
| 467 } | 333 } |
| 468 } | 334 } |
| 469 | 335 |
| 470 } // webkit_glue | 336 } // webkit_glue |
| OLD | NEW |