dom_operations.h revision 513209b27ff55e2841eac0e4120199c23acce758
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 3// found in the LICENSE file. 4 5#ifndef WEBKIT_GLUE_DOM_OPERATIONS_H__ 6#define WEBKIT_GLUE_DOM_OPERATIONS_H__ 7 8#include <string> 9#include <vector> 10 11#include "gfx/size.h" 12#include "googleurl/src/gurl.h" 13 14namespace WebKit { 15class WebDocument; 16class WebElement; 17class WebString; 18class WebView; 19} 20 21// A collection of operations that access the underlying WebKit DOM directly. 22namespace webkit_glue { 23 24// Structure for storage the result of getting all savable resource links 25// for current page. The consumer of the SavableResourcesResult is responsible 26// for keeping these pointers valid for the lifetime of the 27// SavableResourcesResult instance. 28struct SavableResourcesResult { 29 // vector which contains all savable links of sub resource. 30 std::vector<GURL>* resources_list; 31 // vector which contains corresponding all referral links of sub resource, 32 // it matched with links one by one. 33 std::vector<GURL>* referrers_list; 34 // vector which contains all savable links of main frame and sub frames. 35 std::vector<GURL>* frames_list; 36 37 // Constructor. 38 SavableResourcesResult(std::vector<GURL>* resources_list, 39 std::vector<GURL>* referrers_list, 40 std::vector<GURL>* frames_list) 41 : resources_list(resources_list), 42 referrers_list(referrers_list), 43 frames_list(frames_list) { } 44 45 private: 46 DISALLOW_COPY_AND_ASSIGN(SavableResourcesResult); 47}; 48 49// Get all savable resource links from current webview, include main frame 50// and sub-frame. After collecting all savable resource links, this function 51// will send those links to embedder. Return value indicates whether we get 52// all saved resource links successfully. 53bool GetAllSavableResourceLinksForCurrentPage(WebKit::WebView* view, 54 const GURL& page_url, SavableResourcesResult* savable_resources_result, 55 const char** savable_schemes); 56 57// Structure used when installing a web page as an app. Populated via 58// GetApplicationInfo. 59struct WebApplicationInfo { 60 WebApplicationInfo(); 61 ~WebApplicationInfo(); 62 63 struct IconInfo { 64 GURL url; 65 int width; 66 int height; 67 }; 68 69 // Title of the application. This is set from the meta tag whose name is 70 // 'application-name'. 71 string16 title; 72 73 // Description of the application. This is set from the meta tag whose name 74 // is 'description'. 75 string16 description; 76 77 // URL for the app. This is set from the meta tag whose name is 78 // 'application-url'. 79 GURL app_url; 80 81 // Set of available icons. This is set for all link tags whose rel=icon. Only 82 // icons that have a non-zero (width and/or height) are added. 83 std::vector<IconInfo> icons; 84}; 85 86// Parses the icon's size attribute as defined in the HTML 5 spec. Returns true 87// on success, false on errors. On success either all the sizes specified in 88// the attribute are added to sizes, or is_any is set to true. 89// 90// You shouldn't have a need to invoke this directly, it's public for testing. 91bool ParseIconSizes(const string16& text, 92 std::vector<gfx::Size>* sizes, 93 bool* is_any); 94 95// Gets the application info for the specified page. See the description of 96// WebApplicationInfo for details as to where each field comes from. 97void GetApplicationInfo(WebKit::WebView* view, WebApplicationInfo* app_info); 98 99// Invokes pauseAnimationAtTime on the AnimationController associated with the 100// |view|s main frame. 101// This is used by test shell. 102bool PauseAnimationAtTimeOnElementWithId(WebKit::WebView* view, 103 const std::string& animation_name, 104 double time, 105 const std::string& element_id); 106 107// Invokes pauseTransitionAtTime on the AnimationController associated with the 108// |view|s main frame. 109// This is used by test shell. 110bool PauseTransitionAtTimeOnElementWithId(WebKit::WebView* view, 111 const std::string& property_name, 112 double time, 113 const std::string& element_id); 114 115// Returns true if the element with |element_id| as its id has autocomplete 116// on. 117bool ElementDoesAutoCompleteForElementWithId(WebKit::WebView* view, 118 const std::string& element_id); 119 120// Returns the number of animations currently running. 121int NumberOfActiveAnimations(WebKit::WebView* view); 122 123// Returns the value in an elements resource url attribute. For IMG, SCRIPT or 124// INPUT TYPE=image, returns the value in "src". For LINK TYPE=text/css, returns 125// the value in "href". For BODY, TABLE, TR, TD, returns the value in 126// "background". For BLOCKQUOTE, Q, DEL, INS, returns the value in "cite" 127// attribute. Otherwise returns a null WebString. 128WebKit::WebString GetSubResourceLinkFromElement( 129 const WebKit::WebElement& element); 130 131// Puts the meta-elements of |document| that have the attribute |attribute_name| 132// with a value of |attribute_value| in |meta_elements|. 133void GetMetaElementsWithAttribute( 134 WebKit::WebDocument* document, 135 const string16& attribute_name, 136 const string16& atribute_value, 137 std::vector<WebKit::WebElement>* meta_elements); 138 139} // namespace webkit_glue 140 141#endif // WEBKIT_GLUE_DOM_OPERATIONS_H__ 142