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

Side by Side Diff: docs/embedded_browser_framework.md

Issue 1309473002: WIP: Migrate Wiki content over to src/docs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
(Empty)
1 **This document is obsolete. Please visit the chromium embedded framework proje ct page at http://code.google.com/p/chromiumembedded/**
Bons 2015/08/20 20:16:50 propose deletion based on this comment
2
3 # Introduction
4
5 The embedded browser framework will provide standard implementations for the bro wser window, message loop and default functionality (printing, context menus, re source loading, etc), allowing us to offer similar functionality and semantics f or embedded clients on different platforms and technologies (ActiveX, MFC, ObjC, wxWidgets, etc). The embedded client can customize the default functionality a nd handle browser notifications by registering delegate interfaces. The user wi ll be completely insulated from the underlying chromium layer, similar to how th e chromium layer insulates users from WebKit objects.
6
7 # Details
8
9 A fully functional embedded chrome window using this framework might be easily c reated as follows:
10 ```
11 // Define an instance of our CefHandler implementation.
12 CefRefPtr<CefHandler> handler(new MyHandler());
13
14 // Provide information about the parent window, client rectangle, etc.
15 CefWindowInfo info = {...};
16
17 // Create the new browser window object, which eventually results in a call to
18 // MyHandler::HandleAfterCreated().
19 CefBrowser::CreateBrowser(info, false, handler);
20
21 // In the MyHandler::HandleAfterCreated() implementation, navigate to a URL.
22 RetVal MyHandler::HandleAfterCreated(CefRefPtr<CefBrowser> browser)
23 {
24 browser->LoadURL("http://www.google.com");
25 return RV_CONTINUE;
26 }
27 ```
28
29
30 ## Browser Notifications
31
32 Browser notifications are delivered from the browser to the client via registere d delegate interfaces(CefHandler and CefJSHandler).
33
34 * Before Popup. The application can cancel the creation of a popup window.
35 * Before Browse. The application can cancel navigation. Information provided w ith this event includes the URL, post data and request headers.
36 * Load Start. The browser is about to begin loading a URL.
37 * Load End. The browser has finished loading a URL.
38 * Resource Start. The browser is about to begin loading a resource. The appli cation can provide an alternate data source (in-memory buffer, for instance) or cancel the load. The default behavior of the browser implementation is to load the resource in the same manner as test\_shell.
39 * Resource End. The browser has finished loading a resource.
40 * Update Address Bar. Change the address bar to the specified string. This i s sent after navigation is committed and before the page has begun loading.
41 * Update Title. Change the title to the specified string. This is sent while the page is loading.
42 * Before Menu. The browser is about to show a context menu. The application c an either cancel the menu or show a custom menu in its place. The default behav ior of the browser implementation is to show a basic context menu based on the d isposition type.
43 * Get Menu Label. Called one time for each item in a default context menu bef ore that menu is displayed. The application can change the text from the Englis h default to something else (a different language, for instance).
44 * Get Print Header & Footer. Called after the web view is rendered to the pri nt context but before the page is ended. The application can insert a custom he ader/footer string at any of six predefined locations (top left, top center, top right, bottom left, bottom center, bottom right) or do custom drawing on the pr int context. Information provided with this event includes the current URL, tit le, page number, total pages, print context, page bounding box and DPI scale fac tor.
45 * Execute JavaScript. A method has been executed on the "window.embed" object. All JavaScript arguments are provided with this event and the application can specify a return value or cause a JavaScript "no method found" error to be gener ated.
46
47 ## Browser Events
48
49 Browser events are delivered to the browser by the client via host class methods (CefBrowser).
50
51 * Back, Forward, Reload and Stop Load. Control navigation of the target frame.
52 * Undo, Redo, Cut, Copy, Paste, Delete, Select All. Control selection on the target frame.
53 * Print. Print the target frame.
54 * View Source. Save the target frame's HTML source to a temporary file and ope n it in the default text viewing application.
55 * Load URL. Load the specified URL into an optionally specified target frame.
56 * Load String. Load the specified string into the main browser frame with an o ptionally specified dummy URL.
57 * Execute JavaScript. Execute an arbitrary JavaScript command.
58
59 ## Future Capabilities
60
61 The following advanced capabilities will be added to the framework at a later ti me.
62
63 * Support "themes" for customizing user interface elements such as buttons, sc roll bars, etc.
64 * Provide access to and support manipulation of the DOM structure.
65 * Design an easy way to dynamically mix application-provided windows with web content in the browser window.
66 * Provide a method to add objects and functions to the V8 engine.
67
68
69 # Framework Class Definition
70
71 All classes that belong to the Chromium Embedded Framework will be prefixed with "Cef".
72
73 ## Framework Setup and Tear Down
74
75 The UI message loop will be hosted in a single thread created by the framework. The client is responsible for setting up and shutting down this thread for each process that uses the framework by calling CefInitialize() and CefShutdown() re spectively.
76
77 ```
78 // This function should only be called once when the application is started.
79 // Create the thread to host the UI message loop. A return value of true
80 // indicates that it succeeded and false indicates that it failed.
81 bool CefInitialize();
82
83 // This function should only be called once before the application exits.
84 // Shut down the thread hosting the UI message loop and destroy any created
85 // windows.
86 void CefShutdown();
87 ```
88
89 ## Reference Counting
90
91 All framework classes will implement the CefBase interface and all instance poin ters will be handled using the CefRefPtr smart pointer implementation.
92
93 ```
94 // Interface defining the the reference count implementation methods. All
95 // framework classes must implement the CefBase class.
96 class CefBase
97 {
98 public:
99 // The AddRef method increments the reference count for the object. It should
100 // be called for every new copy of a pointer to a given object. The resulting
101 // reference count value is returned and should be used for diagnostic/testing
102 // purposes only.
103 virtual int AddRef() =0;
104
105 // The Release method decrements the reference count for the object. If the
106 // reference count on the object falls to 0, then the object should free
107 // itself from memory. The resulting reference count value is returned and
108 // should be used for diagnostic/testing purposes only.
109 virtual int Release() =0;
110 };
111
112
113 // Smart pointer implementation borrowed from base/ref_counted.h
114 //
115 // A smart pointer class for reference counted objects. Use this class instead
116 // of calling AddRef and Release manually on a reference counted object to
117 // avoid common memory leaks caused by forgetting to Release an object
118 // reference. Sample usage:
119 //
120 // class MyFoo : public CefBase {
121 // ...
122 // };
123 //
124 // void some_function() {
125 // // The MyFoo object that |foo| represents starts with a single
126 // // reference.
127 // CefRefPtr<MyFoo> foo = new MyFoo();
128 // foo->Method(param);
129 // // |foo| is released when this function returns
130 // }
131 //
132 // void some_other_function() {
133 // CefRefPtr<MyFoo> foo = new MyFoo();
134 // ...
135 // foo = NULL; // explicitly releases |foo|
136 // ...
137 // if (foo)
138 // foo->Method(param);
139 // }
140 //
141 // The above examples show how CefRefPtr<T> acts like a pointer to T.
142 // Given two CefRefPtr<T> classes, it is also possible to exchange
143 // references between the two objects, like so:
144 //
145 // {
146 // CefRefPtr<MyFoo> a = new MyFoo();
147 // CefRefPtr<MyFoo> b;
148 //
149 // b.swap(a);
150 // // now, |b| references the MyFoo object, and |a| references NULL.
151 // }
152 //
153 // To make both |a| and |b| in the above example reference the same MyFoo
154 // object, simply use the assignment operator:
155 //
156 // {
157 // CefRefPtr<MyFoo> a = new MyFoo();
158 // CefRefPtr<MyFoo> b;
159 //
160 // b = a;
161 // // now, |a| and |b| each own a reference to the same MyFoo object.
162 // // the reference count of the underlying MyFoo object will be 2.
163 // }
164 //
165 // Reference counted objects can also be passed as function parameters and
166 // used as function return values:
167 //
168 // void some_func_with_param(CefRefPtr<MyFoo> param) {
169 // // A reference is added to the MyFoo object that |param| represents
170 // // during the scope of some_func_with_param() and released when
171 // // some_func_with_param() goes out of scope.
172 // }
173 //
174 // CefRefPtr<MyFoo> some_func_with_retval() {
175 // // The MyFoo object that |foox| represents starts with a single
176 // // reference.
177 // CefRefPtr<MyFoo> foox = new MyFoo();
178 //
179 // // Creating the return value adds an additional reference.
180 // return foox;
181 //
182 // // When some_func_with_retval() goes out of scope the original |foox|
183 // // reference is released.
184 // }
185 //
186 // void and_another_function() {
187 // CefRefPtr<MyFoo> foo = new MyFoo();
188 //
189 // // pass |foo| as a parameter.
190 // some_function(foo);
191 //
192 // CefRefPtr<MyFoo> foo2 = some_func_with_retval();
193 // // Now, since we kept a reference to the some_func_with_retval() return
194 // // value, |foo2| is the only class pointing to the MyFoo object created
195 // in some_func_with_retval(), and it has a reference count of 1.
196 //
197 // some_func_with_retval();
198 // // Now, since we didn't keep a reference to the some_func_with_retval()
199 // // return value, the MyFoo object created in some_func_with_retval()
200 // // will automatically be released.
201 // }
202 //
203 // And in standard containers:
204 //
205 // {
206 // // Create a vector that holds MyFoo objects.
207 // std::vector<CefRefPtr<MyFoo> > MyFooVec;
208 //
209 // // The MyFoo object that |foo| represents starts with a single
210 // // reference.
211 // CefRefPtr<MyFoo> foo = new MyFoo();
212 //
213 // // When the MyFoo object is added to |MyFooVec| the reference count
214 // // is increased to 2.
215 // MyFooVec.push_back(foo);
216 // }
217 //
218 template <class T>
219 class CefRefPtr {
220 public:
221 CefRefPtr() : ptr_(NULL) {
222 }
223
224 CefRefPtr(T* p) : ptr_(p) {
225 if (ptr_)
226 ptr_->AddRef();
227 }
228
229 CefRefPtr(const CefRefPtr<T>& r) : ptr_(r.ptr_) {
230 if (ptr_)
231 ptr_->AddRef();
232 }
233
234 ~CefRefPtr() {
235 if (ptr_)
236 ptr_->Release();
237 }
238
239 T* get() const { return ptr_; }
240 operator T*() const { return ptr_; }
241 T* operator->() const { return ptr_; }
242
243 CefRefPtr<T>& operator=(T* p) {
244 // AddRef first so that self assignment should work
245 if (p)
246 p->AddRef();
247 if (ptr_ )
248 ptr_ ->Release();
249 ptr_ = p;
250 return *this;
251 }
252
253 CefRefPtr<T>& operator=(const CefRefPtr<T>& r) {
254 return *this = r.ptr_;
255 }
256
257 void swap(T** pp) {
258 T* p = ptr_;
259 ptr_ = *pp;
260 *pp = p;
261 }
262
263 void swap(CefRefPtr<T>& r) {
264 swap(&r.ptr_);
265 }
266
267 private:
268 T* ptr_;
269 };
270 ```
271
272 ## Platform Dependant Types
273
274 The framework will define a set of implementation-neutral interfaces and typedef 's that wrap platform-dependent behavior.
275
276 ```
277 #ifdef _WIN32
278 #include <windows.h>
279
280 // Structure representing create window parameters for MS Windows.
281 struct _CefWindowInfoWin
282 {
283 // Standard parameters required by CreateWindowEx()
284 DWORD dwExStyle;
285 std::wstring className;
286 std::wstring windowName;
287 DWORD dwStyle;
288 int x;
289 int y;
290 int nWidth;
291 int nHeight;
292 HWND hWndParent;
293 HMENU hMenu;
294 HINSTANCE hInstance;
295
296 // Handle for the new browser window.
297 HWND hWnd;
298
299 // A parameter that can be used to store client-specific information.
300 CefRefPtr<CefBase> clientInfo;
301 };
302
303 // Use the correct create info structure for the operating system.
304 typedef struct _CefWindowInfoWin CefWindowInfo;
305
306 // Structure representing print context parameters for MS Windows.
307 struct _CefPrintInfoWin
308 {
309 HDC hdc;
310 RECT rect;
311 double scale;
312 };
313
314 // Use the correct print info structure for the operating system.
315 typedef struct _CefPrintInfoWind CefPrintInfo;
316 #endif // _WIN32
317 ```
318
319 ## Thread Safety
320
321 All implementations of framework interfaces must be safe for access from multipl e threads. The CefThreadSafeBase template provides atomic AddRef() and Release( ) implementations. It also provides Lock() and Unlock() methods for synchronizi ng access to blocks of code.
322
323 ```
324 #ifdef _WIN32
325 // Atomic increment and decrement for MS Windows
326 #define CefAtomicIncrement(p) InterlockedIncrement(p)
327 #define CefAtomicDecrement(p) InterlockedDecrement(p)
328
329 // Critical section wrapper for MS Windows
330 class CefCriticalSection
331 {
332 public:
333 CefCriticalSection()
334 {
335 memset(&m_sec, 0, sizeof(CRITICAL_SECTION));
336 InitializeCriticalSection(&m_sec);
337 }
338 ~CefCriticalSection()
339 {
340 DeleteCriticalSection(&m_sec);
341 }
342 void Lock()
343 {
344 EnterCriticalSection(&m_sec);
345 }
346 void Unlock()
347 {
348 LeaveCriticalSection(&m_sec);
349 }
350
351 CRITICAL_SECTION m_sec;
352 };
353 #endif // _WIN32
354
355 // Template that provides atomic implementations of AddRef() and Release()
356 // along with Lock() and Unlock() methods to protect critical sections of
357 // code from simultaneous access by multiple threads.
358 //
359 // The below example demonstrates how to use the CefThreadSafeBase template.
360 //
361 // class MyHandler : public CefThreadSafeBase<CefHandler>
362 // {
363 // std::wstring m_title;
364 //
365 // virtual RetVal HandleTitleChange(const std::wstring& title)
366 // {
367 // Lock(); // Begin protecting code
368 // m_title = title;
369 // Unlock(); // Done protecting code
370 // return RV_HANDLED;
371 // }
372 // ...
373 // }
374 //
375 template <class ClassName>
376 class CefThreadSafeBase : public ClassName
377 {
378 public:
379 CefThreadSafeBase()
380 {
381 m_dwRef = 0L;
382 }
383 ~CefThreadSafeBase()
384 {
385 }
386
387 // Atomic reference increment.
388 int AddRef()
389 {
390 return CefAtomicIncrement(&m_dwRef);
391 }
392
393 // Atomic reference decrement. Delete this object when no references remain.
394 int Release()
395 {
396 int retval = CefAtomicDecrement(&m_dwRef);
397 if(retval == 0)
398 delete this;
399 return retval;
400 }
401
402 // Use the Lock() and Unlock() methods to protect a section of code from
403 // simultaneous access by multiple threads.
404 void Lock() { m_critsec.Lock(); }
405 void Unlock() { m_critsec.Unlock(); }
406
407 protected:
408 long m_dwRef;
409 CefCriticalSection m_critsec;
410 };
411 ```
412
413 ## Framework Interfaces
414
415 And, finally, we have the framework interfaces.
416
417 * **CefBrowser** is the main browser window host class. A new browser window i s created by calling the static CefBrowser::CreateBrowser() method.
418 * **CefHandler** is the main browser delegate interface passed into the CefBro wser::CreateBrowser() method.
419 * **CefRequest** represents request data such as url, method, post data and he aders.
420 * **CefPostData** and **CefPostDataElement** represent the post data that may be part of a request.
421 * **CefStreamReader** and **CefStreamWriter** are simple interfaces for readin g and writing data respectively.
422 * **CefJSHandler** and **CefVariant** are used to implement external JavaScrip t objects provided by the client. JS handlers are assigned via a call to CefBro wser::AddJSHandler().
423
424 ```
425 class CefHandler;
426 class CefRequest;
427 class CefStreamReader;
428 class CefStreamWriter;
429 class CefPostData;
430 class CefPostDataElement;
431 class CefJSHandler;
432 class CefVariant;
433
434
435 // Class used to represent a browser window. All methods exposed by this
436 // class should be thread safe.
437 class CefBrowser : public CefBase
438 {
439 public:
440 // Create a new browser window using the creation parameters specified
441 // by |createInfo|. All values will be copied internally and the actual
442 // window will be created on the UI thread. The |popup| parameter should
443 // be true if the new window is a popup window. This method call will not
444 // block.
445 static void CreateBrowser(CefWindowInfo& createInfo, bool popup,
446 CefRefPtr<CefHandler> handler);
447
448 // Returns true if the browser can navigate backwards.
449 virtual bool CanGoBack() =0;
450 // Navigate backwards.
451 virtual void GoBack() =0;
452 // Returns true if the browser can navigate forwards.
453 virtual bool CanGoForward() =0;
454 // Navigate backwards.
455 virtual void GoForward() =0;
456 // Reload the current page.
457 virtual void Reload() =0;
458 // Stop loading the page.
459 virtual void StopLoad() =0;
460
461 // Define frame target types. Using TF_FOCUSED will target the focused
462 // frame and using TF_MAIN will target the main frame.
463 enum TargetFrame
464 {
465 TF_FOCUSED = 0,
466 TF_MAIN = 1
467 };
468
469 // Execute undo in the target frame.
470 virtual void Undo(TargetFrame targetFrame) =0;
471 // Execute redo in the target frame.
472 virtual void Redo(TargetFrame targetFrame) =0;
473 // Execute cut in the target frame.
474 virtual void Cut(TargetFrame targetFrame) =0;
475 // Execute copy in the target frame.
476 virtual void Copy(TargetFrame targetFrame) =0;
477 // Execute paste in the target frame.
478 virtual void Paste(TargetFrame targetFrame) =0;
479 // Execute delete in the target frame.
480 virtual void Delete(TargetFrame targetFrame) =0;
481 // Execute select all in the target frame.
482 virtual void SelectAll(TargetFrame targetFrame) =0;
483
484 // Execute printing in the target frame. The user will be prompted with
485 // the print dialog appropriate to the operating system.
486 virtual void Print(TargetFrame targetFrame) =0;
487
488 // Save the target frame's HTML source to a temporary file and open it in
489 // the default text viewing application.
490 virtual void ViewSource(TargetFrame targetFrame) =0;
491
492 // Returns the target frame's HTML source as a string.
493 virtual std::wstring GetSource(TargetFrame targetFrame) =0;
494
495 // Returns the target frame's display text as a string.
496 virtual std::wstring GetText(TargetFrame targetFrame) =0;
497
498 // Load the request represented by the |request| object.
499 virtual void LoadRequest(CefRefPtr<CefRequest> request) =0;
500
501 // Convenience method for loading the specified |url| in the optional target
502 // |frame|.
503 virtual void LoadURL(const std::wstring& url, const std::wstring& frame) =0;
504
505 // Load the contents of |string| with the optional dummy target |url|.
506 virtual void LoadString(const std::wstring& string,
507 const std::wstring& url) =0;
508
509 // Load the contents of |stream| with the optional dummy target |url|.
510 virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
511 const std::wstring& url) =0;
512
513 // Returns true if a JS handler with the specified |name| is currently
514 // registered.
515 virtual bool HasJSHandler(const std::wstring& name) =0;
516
517 // Register a new handler tied to the specified JS object |name|. Returns
518 // true if the handler is registered successfully.
519 virtual bool AddJSHandler(const std::wstring& name,
520 CefRefPtr<CefJSHandler> handler) =0;
521
522 // Unregister the JS handler registered with the specified |name|. Returns
523 // true if the handler is unregistered successfully.
524 virtual bool RemoveJSHandler(const std::wstring& name) =0;
525
526 // Returns the JS handler registered with the specified |name|.
527 virtual CefRefPtr<CefJSHandler> GetJSHandler(const std::wstring& name) =0;
528
529 // Retrieve the window information for this browser.
530 virtual void GetWindowInfo(CefWindowInfo& info) =0;
531
532 // Returns true if the window is a popup window.
533 virtual bool IsPopup() =0;
534
535 // Returns the handler for this browser.
536 virtual CefRefPtr<CefHandler> GetHandler() =0;
537 };
538
539
540 // Interface that should be implemented to handle events generated by the
541 // browser window. All methods exposed by this class should be thread safe.
542 // Each method in the interface returns a RetVal value.
543 class CefHandler : public CefBase
544 {
545 public:
546 // Define handler return value types. Returning RV_HANDLED indicates
547 // that the implementation completely handled the method and that no further
548 // processing is required. Returning RV_CONTINUE indicates that the
549 // implementation did not handle the method and that the default handler
550 // should be called.
551 enum RetVal
552 {
553 RV_HANDLED = 0,
554 RV_CONTINUE = 1
555 };
556
557 // Event called before a new window is created. The |parentBrowser| parameter
558 // will point to the parent browser window, if any. The |popup| parameter
559 // will be true if the new window is a popup window. If you create the window
560 // yourself you should populate the window handle member of |createInfo| and
561 // return RV_HANDLED. Otherwise, return RV_CONTINUE and the framework will
562 // create the window. By default, a newly created window will recieve the
563 // same handler as the parent window. To change the handler for the new
564 // window modify the object that |handler| points to.
565 virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
566 CefWindowInfo& createInfo, bool popup,
567 CefRefPtr<CefHandler>& handler) =0;
568
569 // Event called after a new window is created. The return value is currently
570 // ignored.
571 virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser) =0;
572
573 // Event called when the address bar changes. The return value is currently
574 // ignored.
575 virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
576 const std::wstring& url) =0;
577
578 // Event called when the page title changes. The return value is currently
579 // ignored.
580 virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
581 const std::wstring& title) =0;
582
583 // Various browser navigation types supported by chrome.
584 enum NavType
585 {
586 NAVTYPE_LINKCLICKED = 0,
587 NAVTYPE_FORMSUBMITTED,
588 NAVTYPE_BACKFORWARD,
589 NAVTYPE_RELOAD,
590 NAVTYPE_FORMRESUBMITTED,
591 NAVTYPE_OTHER
592 };
593
594 // Event called before browser navigation. The client has an opportunity to
595 // modify the |request| object if desired. Return RV_HANDLED to cancel
596 // navigation.
597 virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
598 CefRefPtr<CefRequest> request,
599 NavType navType, bool isRedirect) =0;
600
601 // Event called when the browser begins loading a page. The return value is
602 // currently ignored.
603 virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser) =0;
604
605 // Event called when the browser is done loading a page. The return value is
606 // currently ignored.
607 virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser) =0;
608
609 // Event called before a resource is loaded. To allow the resource to load
610 // normally return RV_CONTINUE. To redirect the resource to a new url
611 // populate the |redirectUrl| value and return RV_CONTINUE. To specify
612 // data for the resource return a CefStream object in |resourceStream| and
613 // return RV_CONTINUE. To cancel loading of the resource return RV_HANDLED.
614 virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
615 CefRefPtr<CefRequest> request,
616 std::wstring& redirectUrl,
617 CefRefPtr<CefStreamReader> resourceStr eam,
618 int resource_flags) =0;
619
620 // Event called when the browser begins loading a resource. The return value is
621 // currently ignored.
622 virtual RetVal HandleResourceLoadStart(CefRefPtr<CefBrowser> browser) =0;
623
624 // Event called when the browser is done loading a resource. The return value is
625 // currently ignored.
626 virtual RetVal HandleResourceLoadEnd(CefRefPtr<CefBrowser> browser) =0;
627
628 // Various context menu types supported by chrome.
629 enum MenuType
630 {
631 MENUTYPE_NONE = 0,
632 MENUTYPE_PAGE,
633 MENUTYPE_FRAME,
634 MENUTYPE_LINK,
635 MENUTYPE_IMAGE,
636 MENUTYPE_IMAGE_LINK,
637 MENUTYPE_SELECTION,
638 MENUTYPE_EDITABLE
639 };
640
641 // Event called before a context menu is displayed. To cancel display of the
642 // default context menu return RV_HANDLED.
643 virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser,
644 MenuType menuType, int x, int y,
645 const std::wstring& linkUrl,
646 const std::wstring& imageUrl,
647 const std::wstring& pageUrl,
648 const std::wstring& frameUrl,
649 const std::wstring& selectionText,
650 int editFlags) =0;
651
652
653 // Event called to optionally override the default text for a context menu
654 // item. |label| contains the default text and may be modified to substitute
655 // alternate text. The return value is currently ignored.
656 virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser,
657 int menuId, std::wstring& label) =0;
658
659 // Event called to format print headers and footers. |printInfo| contains
660 // platform-specific information about the printer context. |url| is the
661 // URL if the currently printing page, |title| is the title of the currently
662 // printing page, |currentPage| is the current page number and |maxPages| is
663 // the total number of pages. Six default header locations are provided
664 // by the implementation: top left, top center, top right, bottom left,
665 // bottom center and bottom right. To use one of these default locations
666 // just assign a string to the appropriate variable. To draw the header
667 // and footer yourself return RV_HANDLED. Otherwise, populate the approprate
668 // variables and return RV_CONTINUE.
669 virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
670 CefPrintInfo& printInfo,
671 const std::wstring& url,
672 const std::wstring& title,
673 int currentPage, int maxPages,
674 std::wstring& topLeft,
675 std::wstring& topCenter,
676 std::wstring& topRight,
677 std::wstring& bottomLeft,
678 std::wstring& bottomCenter,
679 std::wstring& bottomRight) =0;
680 };
681
682
683 // Class used to represent a web request.
684 class CefRequest : public CefBase
685 {
686 typedef std::map<std::wstring, std::wstring> HeaderMap;
687
688 public:
689 // Create a new CefRequest object.
690 static CefRefPtr<CefRequest> CreateRequest();
691
692 // Fully qualified URL to load.
693 virtual std::wstring GetURL() =0;
694 virtual void SetURL(const std::wstring& url) =0;
695
696 // Optional name of the target frame.
697 virtual std::wstring GetFrame() =0;
698 virtual void SetFrame(const std::wstring& url) =0;
699
700 // Optional request method type, defaulting to POST if post data is provided
701 // and GET otherwise.
702 virtual std::wstring GetMethod() =0;
703 virtual void SetMethod(const std::wstring& url) =0;
704
705 // Optional post data.
706 virtual CefRefPtr<CefPostData> GetPostData() =0;
707 virtual void SetPostData(CefRefPtr<CefPostData> postData) =0;
708
709 // Optional header values.
710 virtual HeaderMap GetHeaderMap() =0;
711 virtual void SetHeaderMap(const HeaderMap& headerMap) =0;
712
713 // Set all values at one time.
714 virtual void Set(const std::wstring& url,
715 const std::wstring& frame,
716 const std::wstring& method,
717 CefRefPtr<CefPostData> postData,
718 const HeaderMap& headerMap) =0;
719 };
720
721
722 // Class used to represent post data for a web request.
723 class CefPostData : public CefBase
724 {
725 typedef std::vector<CefRefPtr<CefPostDataElement> > ElementVector;
726
727 public:
728 // Create a new CefPostData object.
729 static CefRefPtr<CefPostData> CreatePostData();
730
731 // Returns the number of existing post data elements.
732 virtual size_t GetElementCount() =0;
733
734 // Return the post data elements.
735 virtual ElementVector GetElements() =0;
736
737 // Remove the specified post data element. Returns true if the removal
738 // succeeds.
739 virtual bool RemoveElement(CefRefPtr<CefPostDataElement> element) =0;
740
741 // Add the specified post data element. Returns true if the add
742 // succeeds.
743 virtual bool AddElement(CefRefPtr<CefPostDataElement> element) =0;
744 };
745
746
747 // Class used to represent a single element in the request post data.
748 class CefPostDataElement : public CefBase
749 {
750 public:
751 // Post data elements may represent either bytes or files.
752 enum Type
753 {
754 TYPE_BYTES = 0,
755 TYPE_FILE = 1
756 };
757
758 // Create a new CefPostDataElement object.
759 static CefRefPtr<CefPostDataElement> CreatePostDataElement();
760
761 // The post data element will represent a file.
762 virtual void SetToFile(std::wstring& fileName) =0;
763
764 // The post data element will represent bytes. The bytes passed
765 // in will be copied.
766 virtual void SetToBytes(size_t size, void* bytes) =0;
767
768 // Return the type of this post data element.
769 virtual Type GetType() =0;
770
771 // Return the file name.
772 virtual std::wstring GetFile() =0;
773
774 // Return the number of bytes.
775 virtual size_t GetBytesCount() =0;
776
777 // Read up to |size| bytes into |bytes| and return the number of bytes
778 // actually read.
779 virtual size_t GetBytes(size_t size, void *bytes) =0;
780 };
781
782
783 // Class used to read data from a stream.
784 class CefStreamReader : public CefBase
785 {
786 public:
787 // Read raw binary data.
788 virtual size_t Read(void *ptr, size_t size, size_t n) =0;
789
790 // Seek to the specified offset position. |whence| may be any one of
791 // SEEK_CUR, SEEK_END or SEEK_SET.
792 virtual int Seek(long offset, int whence) =0;
793
794 // Return the current offset position.
795 virtual long Tell() =0;
796 };
797
798
799 // Class used to write data to a stream.
800 class CefStreamWriter : public CefBase
801 {
802 public:
803 // Write raw binary data.
804 virtual size_t Write(const void *ptr, size_t size, size_t n) =0;
805
806 // Seek to the specified offset position. |whence| may be any one of
807 // SEEK_CUR, SEEK_END or SEEK_SET.
808 virtual int Seek(long offset, int whence) =0;
809
810 // Return the current offset position.
811 virtual long Tell() =0;
812 };
813
814
815 // Class for implementing external JavaScript objects.
816 class CefJSHandler : public CefBase
817 {
818 typedef std::vector<CefRefPtr<CefVariant> > VariantVector;
819
820 public:
821 // Returns true if the specified method exists.
822 virtual bool HasMethod(CefRefPtr<CefBrowser> browser,
823 const std::wstring& name) =0;
824
825 // Returns true if the specified property exists.
826 virtual bool HasProperty(CefRefPtr<CefBrowser> browser,
827 const std::wstring& name) =0;
828
829 // Set the property value. Returns true if the property is set
830 // successfully.
831 virtual bool SetProperty(CefRefPtr<CefBrowser> browser,
832 const std::wstring& name,
833 CefRefPtr<CefVariant> value) =0;
834
835 // Get the property value.
836 virtual CefRefPtr<CefVariant> GetProperty(CefRefPtr<CefBrowser> browser,
837 const std::wstring& name) =0;
838
839 // Execute a method with the specified argument vector. Returns the method
840 // return value.
841 virtual CefRefPtr<CefVariant> ExecuteMethod(CefRefPtr<CefBrowser> browser,
842 const std::wstring& name,
843 const VariantVector& args) =0;
844 };
845
846
847 // Class that represents multiple data types as a single object.
848 class CefVariant : public CefBase
849 {
850 public:
851 enum Type
852 {
853 TYPE_NULL = 0,
854 TYPE_BOOL,
855 TYPE_INT,
856 TYPE_DOUBLE,
857 TYPE_STRING,
858 TYPE_BOOL_ARRAY,
859 TYPE_INT_ARRAY,
860 TYPE_DOUBLE_ARRAY,
861 TYPE_STRING_ARRAY
862 };
863
864 // Create a new CefVariant object.
865 static CefRefPtr<CefVariant> CreateVariant();
866
867 // Return the variant data type.
868 virtual Type GetType() =0;
869
870 // Assign various data types.
871 virtual void SetNull() =0;
872 virtual void SetBool(bool val) =0;
873 virtual void SetInt(int val) =0;
874 virtual void SetDouble(double val) =0;
875 virtual void SetString(const std::wstring& val) =0;
876 virtual void SetBoolArray(const std::vector<bool>& val) =0;
877 virtual void SetIntArray(const std::vector<int>& val) =0;
878 virtual void SetDoubleArray(const std::vector<double>& val) =0;
879 virtual void SetStringArray(const std::vector<std::wstring>& val) =0;
880
881 // Retrieve various data types.
882 virtual bool GetBool() =0;
883 virtual int GetInt() =0;
884 virtual double GetDouble() =0;
885 virtual std::wstring GetString() =0;
886 virtual void GetBoolArray(std::vector<bool>& val) =0;
887 virtual void GetIntArray(std::vector<int>& val) =0;
888 virtual void GetDoubleArray(std::vector<double>& val) =0;
889 virtual void GetStringArray(std::vector<std::wstring>& val) =0;
890 };
891 ```
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698