1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
13 // * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // ---------------------------------------------------------------------------
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
37 #ifndef CEF_INCLUDE_CEF_BROWSER_H_
38 #define CEF_INCLUDE_CEF_BROWSER_H_
41 #include "include/cef_base.h"
42 #include "include/cef_frame.h"
43 #include "include/cef_process_message.h"
44 #include "include/cef_request_context.h"
52 // Class used to represent a browser window. When used in the browser process
53 // the methods of this class may be called on any thread unless otherwise
54 // indicated in the comments. When used in the render process the methods of
55 // this class may only be called on the main thread.
57 /*--cef(source=library)--*/
58 class CefBrowser : public virtual CefBase {
61 // Returns the browser host object. This method can only be called in the
65 virtual CefRefPtr<CefBrowserHost> GetHost() =0;
68 // Returns true if the browser can navigate backwards.
71 virtual bool CanGoBack() =0;
74 // Navigate backwards.
77 virtual void GoBack() =0;
80 // Returns true if the browser can navigate forwards.
83 virtual bool CanGoForward() =0;
89 virtual void GoForward() =0;
92 // Returns true if the browser is currently loading.
95 virtual bool IsLoading() =0;
98 // Reload the current page.
101 virtual void Reload() =0;
104 // Reload the current page ignoring any cached data.
107 virtual void ReloadIgnoreCache() =0;
110 // Stop loading the page.
113 virtual void StopLoad() =0;
116 // Returns the globally unique identifier for this browser.
119 virtual int GetIdentifier() =0;
122 // Returns true if this object is pointing to the same handle as |that|
126 virtual bool IsSame(CefRefPtr<CefBrowser> that) =0;
129 // Returns true if the window is a popup window.
132 virtual bool IsPopup() =0;
135 // Returns true if a document has been loaded in the browser.
138 virtual bool HasDocument() =0;
141 // Returns the main (top-level) frame for the browser window.
144 virtual CefRefPtr<CefFrame> GetMainFrame() =0;
147 // Returns the focused frame for the browser window.
150 virtual CefRefPtr<CefFrame> GetFocusedFrame() =0;
153 // Returns the frame with the specified identifier, or NULL if not found.
155 /*--cef(capi_name=get_frame_byident)--*/
156 virtual CefRefPtr<CefFrame> GetFrame(int64 identifier) =0;
159 // Returns the frame with the specified name, or NULL if not found.
162 virtual CefRefPtr<CefFrame> GetFrame(const CefString& name) =0;
165 // Returns the number of frames that currently exist.
168 virtual size_t GetFrameCount() =0;
171 // Returns the identifiers of all existing frames.
173 /*--cef(count_func=identifiers:GetFrameCount)--*/
174 virtual void GetFrameIdentifiers(std::vector<int64>& identifiers) =0;
177 // Returns the names of all existing frames.
180 virtual void GetFrameNames(std::vector<CefString>& names) =0;
183 // Send a message to the specified |target_process|. Returns true if the
184 // message was sent successfully.
187 virtual bool SendProcessMessage(CefProcessId target_process,
188 CefRefPtr<CefProcessMessage> message) =0;
193 // Callback interface for CefBrowserHost::RunFileDialog. The methods of this
194 // class will be called on the browser process UI thread.
196 /*--cef(source=client)--*/
197 class CefRunFileDialogCallback : public virtual CefBase {
200 // Called asynchronously after the file dialog is dismissed. If the selection
201 // was successful |file_paths| will be a single value or a list of values
202 // depending on the dialog mode. If the selection was cancelled |file_paths|
205 /*--cef(capi_name=cont)--*/
206 virtual void OnFileDialogDismissed(
207 CefRefPtr<CefBrowserHost> browser_host,
208 const std::vector<CefString>& file_paths) =0;
213 // Class used to represent the browser process aspects of a browser window. The
214 // methods of this class can only be called in the browser process. They may be
215 // called on any thread in that process unless otherwise indicated in the
218 /*--cef(source=library)--*/
219 class CefBrowserHost : public virtual CefBase {
221 typedef cef_file_dialog_mode_t FileDialogMode;
222 typedef cef_mouse_button_type_t MouseButtonType;
223 typedef cef_paint_element_type_t PaintElementType;
226 // Create a new browser window using the window parameters specified by
227 // |windowInfo|. All values will be copied internally and the actual window
228 // will be created on the UI thread. If |request_context| is empty the
229 // global request context will be used. This method can be called on any
230 // browser process thread and will not block.
232 /*--cef(optional_param=client,optional_param=url,
233 optional_param=request_context)--*/
234 static bool CreateBrowser(const CefWindowInfo& windowInfo,
235 CefRefPtr<CefClient> client,
236 const CefString& url,
237 const CefBrowserSettings& settings,
238 CefRefPtr<CefRequestContext> request_context);
241 // Create a new browser window using the window parameters specified by
242 // |windowInfo|. If |request_context| is empty the global request context
243 // will be used. This method can only be called on the browser process UI
246 /*--cef(optional_param=client,optional_param=url,
247 optional_param=request_context)--*/
248 static CefRefPtr<CefBrowser> CreateBrowserSync(
249 const CefWindowInfo& windowInfo,
250 CefRefPtr<CefClient> client,
251 const CefString& url,
252 const CefBrowserSettings& settings,
253 CefRefPtr<CefRequestContext> request_context);
256 // Returns the hosted browser object.
259 virtual CefRefPtr<CefBrowser> GetBrowser() =0;
262 // Call this method before destroying a contained browser window. This method
263 // performs any internal cleanup that may be needed before the browser window
264 // is destroyed. See CefLifeSpanHandler::DoClose() documentation for
265 // additional usage information.
268 virtual void ParentWindowWillClose() =0;
271 // Request that the browser close. The JavaScript 'onbeforeunload' event will
272 // be fired. If |force_close| is false the event handler, if any, will be
273 // allowed to prompt the user and the user can optionally cancel the close.
274 // If |force_close| is true the prompt will not be displayed and the close
275 // will proceed. Results in a call to CefLifeSpanHandler::DoClose() if the
276 // event handler allows the close or if |force_close| is true. See
277 // CefLifeSpanHandler::DoClose() documentation for additional usage
281 virtual void CloseBrowser(bool force_close) =0;
284 // Set whether the browser is focused.
287 virtual void SetFocus(bool focus) =0;
290 // Set whether the window containing the browser is visible
291 // (minimized/unminimized, app hidden/unhidden, etc). Only used on Mac OS X.
294 virtual void SetWindowVisibility(bool visible) =0;
297 // Retrieve the window handle for this browser.
300 virtual CefWindowHandle GetWindowHandle() =0;
303 // Retrieve the window handle of the browser that opened this browser. Will
304 // return NULL for non-popup windows. This method can be used in combination
305 // with custom handling of modal windows.
308 virtual CefWindowHandle GetOpenerWindowHandle() =0;
311 // Returns the client for this browser.
314 virtual CefRefPtr<CefClient> GetClient() =0;
317 // Returns the request context for this browser.
320 virtual CefRefPtr<CefRequestContext> GetRequestContext() =0;
323 // Get the current zoom level. The default zoom level is 0.0. This method can
324 // only be called on the UI thread.
327 virtual double GetZoomLevel() =0;
330 // Change the zoom level to the specified value. Specify 0.0 to reset the
331 // zoom level. If called on the UI thread the change will be applied
332 // immediately. Otherwise, the change will be applied asynchronously on the
336 virtual void SetZoomLevel(double zoomLevel) =0;
339 // Call to run a file chooser dialog. Only a single file chooser dialog may be
340 // pending at any given time. |mode| represents the type of dialog to display.
341 // |title| to the title to be used for the dialog and may be empty to show the
342 // default title ("Open" or "Save" depending on the mode). |default_file_name|
343 // is the default file name to select in the dialog. |accept_types| is a list
344 // of valid lower-cased MIME types or file extensions specified in an input
345 // element and is used to restrict selectable files to such types. |callback|
346 // will be executed after the dialog is dismissed or immediately if another
347 // dialog is already pending. The dialog will be initiated asynchronously on
350 /*--cef(optional_param=title,optional_param=default_file_name,
351 optional_param=accept_types)--*/
352 virtual void RunFileDialog(FileDialogMode mode,
353 const CefString& title,
354 const CefString& default_file_name,
355 const std::vector<CefString>& accept_types,
356 CefRefPtr<CefRunFileDialogCallback> callback) =0;
359 // Download the file at |url| using CefDownloadHandler.
362 virtual void StartDownload(const CefString& url) =0;
365 // Print the current browser contents.
368 virtual void Print() =0;
371 // Search for |searchText|. |identifier| can be used to have multiple searches
372 // running simultaniously. |forward| indicates whether to search forward or
373 // backward within the page. |matchCase| indicates whether the search should
374 // be case-sensitive. |findNext| indicates whether this is the first request
378 virtual void Find(int identifier, const CefString& searchText,
379 bool forward, bool matchCase, bool findNext) =0;
382 // Cancel all searches that are currently going on.
385 virtual void StopFinding(bool clearSelection) =0;
388 // Open developer tools in its own window.
391 virtual void ShowDevTools(const CefWindowInfo& windowInfo,
392 CefRefPtr<CefClient> client,
393 const CefBrowserSettings& settings) =0;
396 // Explicitly close the developer tools window if one exists for this browser
400 virtual void CloseDevTools() =0;
403 // Set whether mouse cursor change is disabled.
406 virtual void SetMouseCursorChangeDisabled(bool disabled) =0;
409 // Returns true if mouse cursor change is disabled.
412 virtual bool IsMouseCursorChangeDisabled() =0;
415 // Returns true if window rendering is disabled.
418 virtual bool IsWindowRenderingDisabled() =0;
421 // Notify the browser that the widget has been resized. The browser will first
422 // call CefRenderHandler::GetViewRect to get the new size and then call
423 // CefRenderHandler::OnPaint asynchronously with the updated regions. This
424 // method is only used when window rendering is disabled.
427 virtual void WasResized() =0;
430 // Notify the browser that it has been hidden or shown. Layouting and
431 // CefRenderHandler::OnPaint notification will stop when the browser is
432 // hidden. This method is only used when window rendering is disabled.
435 virtual void WasHidden(bool hidden) =0;
438 // Send a notification to the browser that the screen info has changed. The
439 // browser will then call CefRenderHandler::GetScreenInfo to update the
440 // screen information with the new values. This simulates moving the webview
441 // window from one display to another, or changing the properties of the
442 // current display. This method is only used when window rendering is
446 virtual void NotifyScreenInfoChanged() =0;
449 // Invalidate the |dirtyRect| region of the view. The browser will call
450 // CefRenderHandler::OnPaint asynchronously with the updated regions. This
451 // method is only used when window rendering is disabled.
454 virtual void Invalidate(const CefRect& dirtyRect, PaintElementType type) =0;
457 // Send a key event to the browser.
460 virtual void SendKeyEvent(const CefKeyEvent& event) =0;
463 // Send a mouse click event to the browser. The |x| and |y| coordinates are
464 // relative to the upper-left corner of the view.
467 virtual void SendMouseClickEvent(const CefMouseEvent& event,
468 MouseButtonType type,
469 bool mouseUp, int clickCount) =0;
472 // Send a mouse move event to the browser. The |x| and |y| coordinates are
473 // relative to the upper-left corner of the view.
476 virtual void SendMouseMoveEvent(const CefMouseEvent& event,
480 // Send a mouse wheel event to the browser. The |x| and |y| coordinates are
481 // relative to the upper-left corner of the view. The |deltaX| and |deltaY|
482 // values represent the movement delta in the X and Y directions respectively.
483 // In order to scroll inside select popups with window rendering disabled
484 // CefRenderHandler::GetScreenPoint should be implemented properly.
487 virtual void SendMouseWheelEvent(const CefMouseEvent& event,
488 int deltaX, int deltaY) =0;
491 // Send a focus event to the browser.
494 virtual void SendFocusEvent(bool setFocus) =0;
497 // Send a capture lost event to the browser.
500 virtual void SendCaptureLostEvent() =0;
503 // Get the NSTextInputContext implementation for enabling IME on Mac when
504 // window rendering is disabled.
506 /*--cef(default_retval=NULL)--*/
507 virtual CefTextInputContext GetNSTextInputContext() =0;
510 // Handles a keyDown event prior to passing it through the NSTextInputClient
514 virtual void HandleKeyEventBeforeTextInputClient(CefEventHandle keyEvent) =0;
517 // Performs any additional actions after NSTextInputClient handles the event.
520 virtual void HandleKeyEventAfterTextInputClient(CefEventHandle keyEvent) =0;
523 #endif // CEF_INCLUDE_CEF_BROWSER_H_