Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: webkit/glue/webframe.h

Issue 164225: Switch to WebFrame from the WebKit API.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webdevtoolsclient_impl.cc ('k') | webkit/glue/webframe_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2009 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_WEBFRAME_H_
6 #define WEBKIT_GLUE_WEBFRAME_H_
7
8 #include <vector>
9
10 #include "base/scoped_ptr.h"
11 #include "base/string16.h"
12 #include "skia/ext/bitmap_platform_device.h"
13 #include "skia/ext/platform_canvas.h"
14 #include "webkit/api/public/WebCanvas.h"
15 #include "webkit/api/public/WebURL.h"
16
17 class GURL;
18 class WebView;
19 class WebTextInput;
20 struct NPObject;
21
22 namespace WebKit {
23 class WebData;
24 class WebDataSource;
25 class WebForm;
26 class WebHistoryItem;
27 class WebString;
28 class WebURLRequest;
29 struct WebConsoleMessage;
30 struct WebFindOptions;
31 struct WebRect;
32 struct WebScriptSource;
33 struct WebSize;
34 struct WebURLError;
35 }
36
37 #if WEBKIT_USING_V8
38 namespace v8 {
39 template <class T> class Local;
40 class Context;
41 }
42 #endif
43
44 // Every frame in a web page is represented by one WebFrame, including the
45 // outermost frame.
46 class WebFrame {
47 public:
48 WebFrame() {}
49
50 // The two functions below retrieve WebFrame instances relating the currently
51 // executing JavaScript. Since JavaScript can make function calls across
52 // frames, though, we need to be more precise.
53 //
54 // For example, imagine that a JS function in frame A calls a function in
55 // frame B, which calls native code, which wants to know what the 'active'
56 // frame is.
57 //
58 // The 'entered context' is the context where execution first entered the
59 // script engine; the context that is at the bottom of the JS function stack.
60 // RetrieveFrameForEnteredContext() would return Frame A in our example.
61 //
62 // The 'current context' is the context the JS engine is currently inside of;
63 // the context that is at the top of the JS function stack.
64 // RetrieveFrameForCurrentContext() would return Frame B in our example.
65 static WebFrame* RetrieveFrameForEnteredContext();
66 static WebFrame* RetrieveFrameForCurrentContext();
67
68 // Binds a C++ class to a JavaScript property of the window object. This
69 // should generally be used via CppBoundClass::BindToJavascript() instead of
70 // calling it directly.
71 virtual void BindToWindowObject(const std::wstring& name,
72 NPObject* object) = 0;
73
74 virtual void CallJSGC() = 0;
75
76 // This grants the currently loaded Document access to all security origins
77 // (including file URLs). Use with care. The access is revoked when a new
78 // document is loaded into this frame.
79 virtual void GrantUniversalAccess() = 0;
80
81 virtual NPObject* GetWindowNPObject() = 0;
82
83 #if WEBKIT_USING_V8
84 // Returns the V8 context for this frame, or an empty handle if there is
85 // none.
86 virtual v8::Local<v8::Context> GetMainWorldScriptContext() = 0;
87 #endif
88
89 // Reload the current document.
90 virtual void Reload() = 0;
91
92 // Loads the given WebURLRequest.
93 virtual void LoadRequest(const WebKit::WebURLRequest& request) = 0;
94
95 // Loads the given WebHistoryItem. This corresponds to a back/forward
96 // navigation.
97 virtual void LoadHistoryItem(const WebKit::WebHistoryItem& item) = 0;
98
99 // Loads the given data with specific mime type and optional text encoding.
100 // For HTML data, base_url indicates the security origin of the document and
101 // is used to resolve links. If specified, unreachable_url is reported via
102 // WebDataSource::unreachableURL. If replace is false, then this data will
103 // be loaded as a normal navigation. Otherwise, the current history item
104 // will be replaced.
105 virtual void LoadData(
106 const WebKit::WebData& data,
107 const WebKit::WebString& mime_type,
108 const WebKit::WebString& text_encoding,
109 const WebKit::WebURL& base_url,
110 const WebKit::WebURL& unreachable_url = WebKit::WebURL(),
111 bool replace = false) = 0;
112
113 // This method is short-hand for calling LoadData, where mime_type is
114 // "text/html" and text_encoding is "UTF-8".
115 virtual void LoadHTMLString(
116 const WebKit::WebData& html,
117 const WebKit::WebURL& base_url,
118 const WebKit::WebURL& unreachable_url = WebKit::WebURL(),
119 bool replace = false) = 0;
120
121 // Called to associate the WebURLRequest with this frame. The request will
122 // be modified to inherit parameters that allow it to be loaded. This method
123 // ends up triggering WebViewDelegate::WillSendRequest.
124 virtual void DispatchWillSendRequest(WebKit::WebURLRequest* request) = 0;
125
126 // Called from within WebViewDelegate::DidReceiveDocumentData to commit data
127 // for the frame that will be used to construct the frame's document.
128 virtual void CommitDocumentData(const char* data, size_t data_len) = 0;
129
130 // Executes JavaScript in the web frame.
131 virtual void ExecuteScript(const WebKit::WebScriptSource& source) = 0;
132
133 // Executes JavaScript in a new context associated with the web frame. The
134 // script gets its own global scope and its own prototypes for intrinsic
135 // JavaScript objects (String, Array, and so-on). It shares the wrappers for
136 // all DOM nodes and DOM constructors. extension_group is an
137 // embedder-provided specifier that controls which v8 extensions are loaded
138 // into the new context - see WebKit::registerExtension for the corresponding
139 // specifier.
140 virtual void ExecuteScriptInNewContext(
141 const WebKit::WebScriptSource* sources, int num_sources,
142 int extension_group) = 0;
143
144 // Executes JavaScript in a new world associated with the web frame. The
145 // script gets its own global scope and its own prototypes for intrinsic
146 // JavaScript objects (String, Array, and so-on). It also gets its own
147 // wrappers for all DOM nodes and DOM constructors. extension_group is an
148 // embedder-provided specifier that controls which v8 extensions are loaded
149 // into the new context - see WebKit::registerExtension for the corresponding
150 // specifier.
151 virtual void ExecuteScriptInNewWorld(
152 const WebKit::WebScriptSource* sources, int num_sources,
153 int extension_group) = 0;
154
155 // Inserts the given CSS styles at the beginning of the document.
156 virtual bool InsertCSSStyles(const std::string& css) = 0;
157
158 // Returns the WebHistoryItem representing the state of the previous page
159 // load for later use when loading. The previous page is the page that was
160 // loaded before DidCommitLoadForFrame was received.
161 //
162 // Returns a null item if there is no valid state to return (for example,
163 // there is no previous item). Returns true if the previous item's state was
164 // retrieved, even if that state may be empty.
165 virtual WebKit::WebHistoryItem GetPreviousHistoryItem() const = 0;
166
167 // Returns the WebHistoryItem representing the state of the current page load
168 // for later use when loading.
169 //
170 // Returns a null item if there is no valid state to return (for example,
171 // there is no previous item). Returns true if the current item's state was
172 // retrieved, even if that state may be empty.
173 virtual WebKit::WebHistoryItem GetCurrentHistoryItem() const = 0;
174
175 // Returns the current URL of the frame, or an empty GURL if there is no
176 // URL to retrieve (for example, the frame may never have had any content).
177 virtual GURL GetURL() const = 0;
178
179 // Returns the URL to the favorite icon for the frame. An empty GURL is
180 // returned if the frame has not finished loading, or the frame's URL
181 // protocol is not http or https.
182 virtual GURL GetFavIconURL() const = 0;
183
184 // Returns the URL to the OpenSearch description document for the frame. If
185 // the page does not have a valid document, an empty GURL is returned.
186 virtual GURL GetOSDDURL() const = 0;
187
188 // Return the minPrefWidth of the content contained in the current Document
189 virtual int GetContentsPreferredWidth() const = 0;
190
191 // Returns the committed data source, which is the last data source that has
192 // successfully started loading. Will return NULL if no provisional data
193 // has been committed.
194 virtual WebKit::WebDataSource* GetDataSource() const = 0;
195
196 // Returns the provisional data source, which is a data source where a
197 // request has been made, but we are not sure if we will use data from it
198 // (for example, it may be an invalid URL). When the provisional load is
199 // "committed," it will become the "real" data source (see GetDataSource
200 // above) and the provisional data source will be NULL.
201 virtual WebKit::WebDataSource* GetProvisionalDataSource() const = 0;
202
203 //
204 // @method stopLoading
205 // @discussion Stop any pending loads on the frame's data source,
206 // and its children.
207 // - (void)stopLoading;
208 virtual void StopLoading() = 0;
209
210 // Returns true if this frame is loading its main resource or a subresource.
211 virtual bool IsLoading() const = 0;
212
213 // Returns the frame that opened this frame, or NULL if this window has no
214 // opener.
215 virtual WebFrame* GetOpener() const = 0;
216
217 // Returns the frame containing this frame, or NULL of this is a top level
218 // frame with no parent.
219 virtual WebFrame* GetParent() const = 0;
220
221 // Returns the top-most frame in the frame hierarchy containing this frame.
222 virtual WebFrame* GetTop() const = 0;
223
224 // Returns the child frame with the given xpath.
225 // The document of this frame is used as the context node.
226 // The xpath may need a recursive traversal if non-trivial
227 // A non-trivial xpath will contain a combination of xpaths
228 // (delimited by '\n') leading to an inner subframe.
229 //
230 // Example: /html/body/iframe/\n/html/body/div/iframe/\n/frameset/frame[0]
231 // can be broken into 3 xpaths
232 // /html/body/iframe evaluates to an iframe within the root frame
233 // /html/body/div/iframe evaluates to an iframe within the level-1 iframe
234 // /frameset/frame[0] evaluates to first frame within the level-2 iframe
235 virtual WebFrame* GetChildFrame(const std::wstring& xpath) const = 0;
236
237 // Returns a pointer to the WebView that contains this WebFrame. This
238 // pointer is not AddRef'd and is only valid for the lifetime of the WebFrame
239 // unless it is AddRef'd separately by the caller.
240 virtual WebView* GetView() const = 0;
241
242 // Returns a vector of WebForms (corresponds to document.forms).
243 virtual void GetForms(std::vector<WebKit::WebForm>* forms) const = 0;
244
245 // Returns the serialization of the frame's security origin.
246 virtual std::string GetSecurityOrigin() const = 0;
247
248 // Fills the contents of this frame into the given string. If the text is
249 // longer than max_chars, it will be clipped to that length. Warning: this
250 // function may be slow depending on the number of characters retrieved and
251 // page complexity. For a typically sized page, expect it to take on the
252 // order of milliseconds.
253 //
254 // If there is room, subframe text will be recursively appended. Each frame
255 // will be separated by an empty line.
256 virtual void GetContentAsPlainText(int max_chars,
257 std::wstring* text) const = 0;
258
259 // Searches a frame for a given string.
260 //
261 // If a match is found, this function will select it (scrolling down to make
262 // it visible if needed) and fill in the IntRect (selection_rect) with the
263 // location of where the match was found (in screen coordinates).
264 //
265 // If no match is found, this function clears all tickmarks and highlighting.
266 //
267 // Returns true if the search string was found, false otherwise.
268 virtual bool Find(int request_id,
269 const string16& search_text,
270 const WebKit::WebFindOptions& options,
271 bool wrap_within_frame,
272 WebKit::WebRect* selection_rect) = 0;
273
274 // Notifies the frame that we are no longer interested in searching. This will
275 // abort any asynchronous scoping effort already under way (see the function
276 // ScopeStringMatches for details) and erase all tick-marks and highlighting
277 // from the previous search. If |clear_selection| is true, it will also make
278 // sure the end state for the Find operation does not leave a selection.
279 // This can occur when the user clears the search string but does not close
280 // the find box.
281 virtual void StopFinding(bool clear_selection) = 0;
282
283 // Counts how many times a particular string occurs within the frame. It
284 // also retrieves the location of the string and updates a vector in the frame
285 // so that tick-marks and highlighting can be drawn. This function does its
286 // work asynchronously, by running for a certain time-slice and then
287 // scheduling itself (co-operative multitasking) to be invoked later
288 // (repeating the process until all matches have been found). This allows
289 // multiple frames to be searched at the same time and provides a way to
290 // cancel at any time (see CancelPendingScopingEffort). The parameter Request
291 // specifies what to look for and Reset signals whether this is a brand new
292 // request or a continuation of the last scoping effort.
293 virtual void ScopeStringMatches(int request_id,
294 const string16& search_text,
295 const WebKit::WebFindOptions& options,
296 bool reset) = 0;
297
298 // Cancels any outstanding requests for scoping string matches on a frame.
299 virtual void CancelPendingScopingEffort() = 0;
300
301 // This function is called on the mainframe during the scoping effort to keep
302 // a running tally of the accumulated total match-count for all frames. After
303 // updating the count it will notify the render-view about the new count.
304 virtual void IncreaseMatchCount(int count, int request_id) = 0;
305
306 // Notifies the webview-delegate about a new selection rect. This will result
307 // in the browser getting notified. For more information see WebViewDelegate.
308 virtual void ReportFindInPageSelection(const WebKit::WebRect& selection_rect,
309 int active_match_ordinal,
310 int request_id) = 0;
311
312 // This function is called on the mainframe to reset the total number of
313 // matches found during the scoping effort.
314 virtual void ResetMatchCount() = 0;
315
316 // Returns true if the frame is visible (defined as width > 0 and height > 0).
317 virtual bool Visible() = 0;
318
319 // Selects all the text in the frame.
320 virtual void SelectAll() = 0;
321
322 //
323 // - (void)copy:(id)sender;
324 virtual void Copy() = 0;
325
326 //
327 // - (void)cut:(id)sender;
328 virtual void Cut() = 0;
329
330 //
331 // - (void)paste:(id)sender;
332 virtual void Paste() = 0;
333
334 // Replace the selection text by a given text.
335 virtual void Replace(const std::wstring& text) = 0;
336
337 // Toggle spell check on and off.
338 virtual void ToggleSpellCheck() = 0;
339
340 // Return whether spell check is enabled or not in this frame.
341 virtual bool SpellCheckEnabled() = 0;
342
343 //
344 // - (void)delete:(id)sender;
345 // Delete as in similar to Cut, not as in teardown
346 virtual void Delete() = 0;
347
348 // Undo the last text editing command.
349 virtual void Undo() = 0;
350
351 // Redo the last undone text editing command.
352 virtual void Redo() = 0;
353
354 // Clear any text selection in the frame.
355 virtual void ClearSelection() = 0;
356
357 // Checks if there is currently a selected area (indicates that GetSelection
358 // would return a non-empty string).
359 virtual bool HasSelection() = 0;
360
361 // Returns the selected text if there is any. If |as_html| is true, returns
362 // the selection as HTML. The return value is encoded in utf-8.
363 virtual std::string GetSelection(bool as_html) = 0;
364
365 // Returns the full HTML of the page.
366 virtual std::string GetFullPageHtml() = 0;
367
368 // This function sets a flag within WebKit to instruct it to render the page
369 // as View-Source (showing the HTML source for the page).
370 virtual void SetInViewSourceMode(bool enable) = 0;
371
372 // This function returns whether this frame is in "view-source" mode.
373 virtual bool GetInViewSourceMode() const = 0;
374
375 // Returns the frame name.
376 virtual std::wstring GetName() = 0;
377
378 // Returns a pointer to the WebTextInput object associated with the frame.
379 // The caller does not own the object returned.
380 virtual WebTextInput* GetTextInput() = 0;
381
382 // Executes a webkit editor command. The supported commands are a
383 // superset of those accepted by javascript:document.execCommand().
384 // This method is exposed in order to implement
385 // javascript:layoutTestController.execCommand()
386 virtual bool ExecuteEditCommandByName(const std::string& name,
387 const std::string& value) = 0;
388
389 // Checks whether a webkit editor command is currently enabled. This
390 // method is exposed in order to implement
391 // javascript:layoutTestController.isCommandEnabled()
392 virtual bool IsEditCommandEnabled(const std::string& name) = 0;
393
394 // Adds a message to the frame's console.
395 virtual void AddMessageToConsole(const WebKit::WebConsoleMessage&) = 0;
396
397 // The current scroll offset from the top of frame in pixels.
398 virtual WebKit::WebSize ScrollOffset() const = 0;
399
400 // Reformats the WebFrame for printing. page_size is the page size in
401 // pixels. Returns the number of pages that can be printed at the given page
402 // size.
403 virtual int PrintBegin(const WebKit::WebSize& page_size) = 0;
404
405 // Prints one page, and returns the calculated page shrinking factor (usually
406 // between 1/1.25 and 1/2). Returns 0 if the page number is invalid or not
407 // in printing mode.
408 virtual float PrintPage(int page_to_print, WebKit::WebCanvas* canvas) = 0;
409
410 // Reformats the WebFrame for screen display.
411 virtual void PrintEnd() = 0;
412
413 // Only for test_shell
414 virtual int PendingFrameUnloadEventCount() const = 0;
415
416 protected:
417 virtual ~WebFrame() {}
418
419 private:
420 DISALLOW_COPY_AND_ASSIGN(WebFrame);
421 };
422
423 #endif // WEBKIT_GLUE_WEBFRAME_H_
OLDNEW
« no previous file with comments | « webkit/glue/webdevtoolsclient_impl.cc ('k') | webkit/glue/webframe_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698