diff --git a/include/cef.h b/include/cef.h index 68d793bf3..facb59c97 100644 --- a/include/cef.h +++ b/include/cef.h @@ -58,6 +58,7 @@ class CefStreamWriter; class CefTask; class CefV8Handler; class CefV8Value; +class CefPopupFeatures; // This function should only be called once when the application is started. @@ -547,17 +548,20 @@ public: // Event called before a new window is created. The |parentBrowser| parameter // will point to the parent browser window, if any. The |popup| parameter - // will be true if the new window is a popup window. If you create the window - // yourself you should populate the window handle member of |createInfo| and - // return RV_HANDLED. Otherwise, return RV_CONTINUE and the framework will - // create the window. By default, a newly created window will recieve the - // same handler as the parent window. To change the handler for the new - // window modify the object that |handler| points to. + // will be true if the new window is a popup window, in which case + // |popupFeatures| will contain information about the style of popup window + // requested. If you create the window yourself you should populate the window + // handle member of |createInfo| and return RV_HANDLED. Otherwise, return + // RV_CONTINUE and the framework will create the window. By default, a newly + // created window will recieve the same handler as the parent window. To + // change the handler for the new window modify the object that |handler| + // points to. /*--cef()--*/ virtual RetVal HandleBeforeCreated(CefRefPtr parentBrowser, CefWindowInfo& windowInfo, bool popup, CefRefPtr& handler, - std::wstring& url) =0; + std::wstring& url, + const CefPopupFeatures& popupFeatures) =0; // Event called after a new window is created. The return value is currently // ignored. @@ -1482,4 +1486,95 @@ public: virtual bool Eof() =0; }; + +// Class representing popup window features. +class CefPopupFeatures : public cef_popup_features_t +{ +public: + CefPopupFeatures() + { + Init(); + } + ~CefPopupFeatures() + { + if(additionalFeatures) + cef_string_list_free(additionalFeatures); + } + + CefPopupFeatures(const CefPopupFeatures& r) + { + Init(); + *this = r; + } + CefPopupFeatures(const cef_popup_features_t& r) + { + Init(); + *this = r; + } + + void Init() + { + x = 0; + xSet = false; + y = 0; + ySet = false; + width = 0; + widthSet = false; + height = 0; + heightSet = false; + + menuBarVisible = true; + statusBarVisible = true; + toolBarVisible = true; + locationBarVisible = true; + scrollbarsVisible = true; + resizable = true; + + fullscreen = false; + dialog = false; + additionalFeatures = NULL; + } + + CefPopupFeatures& operator=(const CefPopupFeatures& r) + { + return operator=(static_cast(r)); + } + + CefPopupFeatures& operator=(const cef_popup_features_t& r) + { + if(additionalFeatures) + cef_string_list_free(additionalFeatures); + if(r.additionalFeatures) { + additionalFeatures = cef_string_list_alloc(); + unsigned int size = cef_string_list_size(r.additionalFeatures); + for(unsigned int i = 0; i < size; ++i) { + cef_string_t feature = cef_string_list_value(r.additionalFeatures, i); + cef_string_list_append(additionalFeatures, feature); + cef_string_free(feature); + } + } + else { + additionalFeatures = NULL; + } + + x = r.x; + xSet = r.xSet; + y = r.y; + ySet = r.ySet; + width = r.width; + widthSet = r.widthSet; + height = r.height; + heightSet = r.heightSet; + menuBarVisible = r.menuBarVisible; + statusBarVisible = r.statusBarVisible; + toolBarVisible = r.toolBarVisible; + locationBarVisible = r.locationBarVisible; + scrollbarsVisible = r.scrollbarsVisible; + resizable = r.resizable; + fullscreen = r.fullscreen; + dialog = r.dialog; + return *this; + } +}; + #endif // _CEF_H diff --git a/include/cef_capi.h b/include/cef_capi.h index 2d07fdcdc..222c4d035 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -371,16 +371,19 @@ typedef struct _cef_handler_t // Event called before a new window is created. The |parentBrowser| parameter // will point to the parent browser window, if any. The |popup| parameter will - // be true (1) if the new window is a popup window. If you create the window - // yourself you should populate the window handle member of |createInfo| and - // return RV_HANDLED. Otherwise, return RV_CONTINUE and the framework will - // create the window. By default, a newly created window will recieve the - // same handler as the parent window. To change the handler for the new - // window modify the object that |handler| points to. + // be true (1) if the new window is a popup window, in which case + // |popupFeatures| will contain information about the style of popup window + // requested. If you create the window yourself you should populate the window + // handle member of |createInfo| and return RV_HANDLED. Otherwise, return + // RV_CONTINUE and the framework will create the window. By default, a newly + // created window will recieve the same handler as the parent window. To + // change the handler for the new window modify the object that |handler| + // points to. enum cef_retval_t (CEF_CALLBACK *handle_before_created)( struct _cef_handler_t* self, struct _cef_browser_t* parentBrowser, struct _cef_window_info_t* windowInfo, int popup, - struct _cef_handler_t** handler, cef_string_t* url); + struct _cef_handler_t** handler, cef_string_t* url, + const struct _cef_popup_features_t* popupFeatures); // Event called after a new window is created. The return value is currently // ignored. diff --git a/include/cef_types.h b/include/cef_types.h index 9b3b10b95..7574cf804 100644 --- a/include/cef_types.h +++ b/include/cef_types.h @@ -35,6 +35,7 @@ extern "C" { #endif +#include "cef_string_list.h" // Bring in platform-specific definitions. #if defined(_WIN32) @@ -286,7 +287,7 @@ struct cef_print_margins double footer; }; -// Page orientation for printing +// Page orientation for printing. enum cef_page_orientation { PORTRAIT = 0, @@ -330,6 +331,30 @@ enum cef_xml_node_type_t XML_NODE_COMMENT, }; +// Popup window features. +typedef struct _cef_popup_features_t +{ + int x; + bool xSet; + int y; + bool ySet; + int width; + bool widthSet; + int height; + bool heightSet; + + bool menuBarVisible; + bool statusBarVisible; + bool toolBarVisible; + bool locationBarVisible; + bool scrollbarsVisible; + bool resizable; + + bool fullscreen; + bool dialog; + cef_string_list_t additionalFeatures; +} cef_popup_features_t; + #ifdef __cplusplus } #endif diff --git a/libcef/browser_impl.cc b/libcef/browser_impl.cc index 26b5c9fe2..28a6d8596 100644 --- a/libcef/browser_impl.cc +++ b/libcef/browser_impl.cc @@ -499,8 +499,8 @@ bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup, { // Give the handler an opportunity to modify window attributes, handler, // or cancel the window creation. - CefHandler::RetVal rv = - handler->HandleBeforeCreated(NULL, windowInfo, popup, handler, newUrl); + CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo, + popup, handler, newUrl, CefPopupFeatures()); if(rv == RV_HANDLED) return false; } @@ -513,9 +513,7 @@ bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup, } CefRefPtr CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo, - bool popup, - CefRefPtr handler, - const std::wstring& url) + bool popup, CefRefPtr handler, const std::wstring& url) { if(!_Context.get() || !CefThread::CurrentlyOn(CefThread::UI)) return NULL; @@ -528,7 +526,7 @@ CefRefPtr CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo, // Give the handler an opportunity to modify window attributes, handler, // or cancel the window creation. CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo, - popup, handler, newUrl); + popup, handler, newUrl, CefPopupFeatures()); if(rv == RV_HANDLED) return false; } @@ -792,7 +790,8 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry, return true; } -CefRefPtr CefBrowserImpl::UIT_CreatePopupWindow(const std::wstring& url) +CefRefPtr CefBrowserImpl::UIT_CreatePopupWindow( + const std::wstring& url, const CefPopupFeatures& features) { REQUIRE_UIT(); @@ -807,8 +806,8 @@ CefRefPtr CefBrowserImpl::UIT_CreatePopupWindow(const std::wstri { // Give the handler an opportunity to modify window attributes, handler, // or cancel the window creation. - CefHandler::RetVal rv = - handler_->HandleBeforeCreated(this, info, true, handler, newUrl); + CefHandler::RetVal rv = handler_->HandleBeforeCreated(this, info, true, + handler, newUrl, features); if(rv == RV_HANDLED) return NULL; } diff --git a/libcef/browser_impl.h b/libcef/browser_impl.h index 35be6e7be..fdf2d330e 100644 --- a/libcef/browser_impl.h +++ b/libcef/browser_impl.h @@ -188,7 +188,8 @@ public: bool ignoreCahce); void UIT_SetFocus(WebWidgetHost* host, bool enable); - CefRefPtr UIT_CreatePopupWindow(const std::wstring& url); + CefRefPtr UIT_CreatePopupWindow(const std::wstring& url, + const CefPopupFeatures& features); WebKit::WebWidget* UIT_CreatePopupWidget(); void UIT_ClosePopupWidget(); diff --git a/libcef/browser_webview_delegate.cc b/libcef/browser_webview_delegate.cc index 42a4574fa..e8ca6b427 100644 --- a/libcef/browser_webview_delegate.cc +++ b/libcef/browser_webview_delegate.cc @@ -51,6 +51,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" #include "third_party/WebKit/WebKit/chromium/public/WebView.h" +#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h" #include "webkit/appcache/web_application_cache_host_impl.h" #include "webkit/glue/glue_serialize.h" #include "webkit/glue/media/buffered_data_source.h" @@ -126,6 +127,38 @@ namespace { int next_page_id_ = 1; +void TranslatePopupFeatures(const WebWindowFeatures& webKitFeatures, + CefPopupFeatures& features) +{ + features.x = static_cast(webKitFeatures.x); + features.xSet = webKitFeatures.xSet; + features.y = static_cast(webKitFeatures.y); + features.ySet = webKitFeatures.ySet; + features.width = static_cast(webKitFeatures.width); + features.widthSet = webKitFeatures.widthSet; + features.height = static_cast(webKitFeatures.height); + features.heightSet = webKitFeatures.heightSet; + + features.menuBarVisible = webKitFeatures.menuBarVisible; + features.statusBarVisible = webKitFeatures.statusBarVisible; + features.toolBarVisible = webKitFeatures.toolBarVisible; + features.locationBarVisible = webKitFeatures.locationBarVisible; + features.scrollbarsVisible = webKitFeatures.scrollbarsVisible; + features.resizable = webKitFeatures.resizable; + + features.fullscreen = webKitFeatures.fullscreen; + features.dialog = webKitFeatures.dialog; + features.additionalFeatures = NULL; + if (webKitFeatures.additionalFeatures.size() > 0) + features.additionalFeatures = cef_string_list_alloc(); + + for(unsigned int i = 0; i < webKitFeatures.additionalFeatures.size(); ++i) { + cef_string_list_append(features.additionalFeatures, + webkit_glue::WebStringToStdWString( + webKitFeatures.additionalFeatures[i]).c_str()); + } +} + } // namespace // WebViewDelegate ----------------------------------------------------------- @@ -150,8 +183,10 @@ void BrowserWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) { WebView* BrowserWebViewDelegate::createView(WebFrame* creator, const WebWindowFeatures& features, const WebString& name) { + CefPopupFeatures cefFeatures; + TranslatePopupFeatures(features, cefFeatures); CefRefPtr browser = - browser_->UIT_CreatePopupWindow(std::wstring()); + browser_->UIT_CreatePopupWindow(std::wstring(), cefFeatures); return browser.get() ? browser->GetWebView() : NULL; } @@ -247,10 +282,9 @@ bool BrowserWebViewDelegate::shouldInsertText(const WebString& text, return browser_->UIT_AllowEditing(); } -bool BrowserWebViewDelegate::shouldChangeSelectedRange(const WebRange& from_range, - const WebRange& to_range, - WebTextAffinity affinity, - bool still_selecting) { +bool BrowserWebViewDelegate::shouldChangeSelectedRange( + const WebRange& from_range, const WebRange& to_range, + WebTextAffinity affinity, bool still_selecting) { return browser_->UIT_AllowEditing(); } @@ -410,7 +444,8 @@ void BrowserWebViewDelegate::setToolTipText( std::wstring tooltipText(UTF8ToWide(webkit_glue::WebStringToStdString(text))); CefRefPtr handler = browser_->GetHandler(); - if(handler.get() && handler->HandleTooltip(browser_, tooltipText) == RV_CONTINUE){ + if(handler.get() && handler->HandleTooltip(browser_, tooltipText) + == RV_CONTINUE){ GetWidgetHost()->SetTooltipText(tooltipText); } } @@ -581,7 +616,8 @@ void BrowserWebViewDelegate::loadURLExternally( WebFrame* frame, const WebURLRequest& request, WebNavigationPolicy policy) { DCHECK_NE(policy, WebKit::WebNavigationPolicyCurrentTab); - browser_->UIT_CreatePopupWindow(UTF8ToWide(request.url().spec().data())); + browser_->UIT_CreatePopupWindow(UTF8ToWide(request.url().spec().data()), + CefPopupFeatures()); } WebNavigationPolicy BrowserWebViewDelegate::decidePolicyForNavigation( diff --git a/libcef_dll/cpptoc/handler_cpptoc.cc b/libcef_dll/cpptoc/handler_cpptoc.cc index da9dac90a..7ee5c0d10 100644 --- a/libcef_dll/cpptoc/handler_cpptoc.cc +++ b/libcef_dll/cpptoc/handler_cpptoc.cc @@ -25,7 +25,7 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_created( struct _cef_handler_t* self, cef_browser_t* parentBrowser, cef_window_info_t* windowInfo, int popup, struct _cef_handler_t** handler, - cef_string_t* url) + cef_string_t* url, const struct _cef_popup_features_t* popupFeatures) { DCHECK(self); DCHECK(windowInfo); @@ -35,6 +35,7 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_created( return RV_CONTINUE; CefWindowInfo wndInfo(*windowInfo); + CefPopupFeatures features(*popupFeatures); // |newHandler| will start off pointing to the current handler. CefRefPtr handlerPtr = CefHandlerCppToC::Unwrap(*handler); @@ -50,7 +51,7 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_created( urlStr = *url; enum cef_retval_t rv = CefHandlerCppToC::Get(self)->HandleBeforeCreated( - browserPtr, wndInfo, popup?true:false, handlerPtr, urlStr); + browserPtr, wndInfo, popup?true:false, handlerPtr, urlStr, features); transfer_string_contents(urlStr, url); diff --git a/libcef_dll/ctocpp/handler_ctocpp.cc b/libcef_dll/ctocpp/handler_ctocpp.cc index 2a47440c9..ef4f5cea5 100644 --- a/libcef_dll/ctocpp/handler_ctocpp.cc +++ b/libcef_dll/ctocpp/handler_ctocpp.cc @@ -24,7 +24,8 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeCreated( CefRefPtr parentBrowser, CefWindowInfo& windowInfo, bool popup, - CefRefPtr& handler, std::wstring& url) + CefRefPtr& handler, std::wstring& url, + const CefPopupFeatures& popupFeatures) { if(CEF_MEMBER_MISSING(struct_, handle_before_created)) return RV_CONTINUE; @@ -43,7 +44,7 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeCreated( urlRet = cef_string_alloc(url.c_str()); cef_retval_t rv = struct_->handle_before_created(struct_, - browserStruct, &windowInfo, popup, &handlerStruct, &urlRet); + browserStruct, &windowInfo, popup, &handlerStruct, &urlRet, &popupFeatures); if(handlerStruct && handlerStruct != origHandlerStruct) { // The handler was changed. diff --git a/libcef_dll/ctocpp/handler_ctocpp.h b/libcef_dll/ctocpp/handler_ctocpp.h index ac9600474..c9c408c3e 100644 --- a/libcef_dll/ctocpp/handler_ctocpp.h +++ b/libcef_dll/ctocpp/handler_ctocpp.h @@ -33,7 +33,7 @@ public: // CefHandler methods virtual RetVal HandleBeforeCreated(CefRefPtr parentBrowser, CefWindowInfo& windowInfo, bool popup, CefRefPtr& handler, - std::wstring& url); + std::wstring& url, const CefPopupFeatures& popupFeatures); virtual RetVal HandleAfterCreated(CefRefPtr browser); virtual RetVal HandleAddressChange(CefRefPtr browser, CefRefPtr frame, const std::wstring& url); diff --git a/tests/cefclient/cefclient.h b/tests/cefclient/cefclient.h index 607abfdbb..2173ba24d 100644 --- a/tests/cefclient/cefclient.h +++ b/tests/cefclient/cefclient.h @@ -43,7 +43,8 @@ public: virtual RetVal HandleBeforeCreated(CefRefPtr parentBrowser, CefWindowInfo& createInfo, bool popup, CefRefPtr& handler, - std::wstring& url) + std::wstring& url, + const CefPopupFeatures& popupFeatures) { return RV_CONTINUE; } diff --git a/tests/unittests/test_handler.h b/tests/unittests/test_handler.h index dff0c9cac..95c80c972 100644 --- a/tests/unittests/test_handler.h +++ b/tests/unittests/test_handler.h @@ -27,7 +27,8 @@ public: virtual RetVal HandleBeforeCreated(CefRefPtr parentBrowser, CefWindowInfo& createInfo, bool popup, CefRefPtr& handler, - std::wstring& url) + std::wstring& url, + const CefPopupFeatures& popupFeatures) { return RV_CONTINUE; } diff --git a/tools/cef_parser.py b/tools/cef_parser.py index 2a292bb05..bf6b52cad 100644 --- a/tools/cef_parser.py +++ b/tools/cef_parser.py @@ -1056,7 +1056,8 @@ class obj_analysis: # check for simple direct translations structuretypes = { 'CefPrintInfo' : 'cef_print_info_t', - 'CefWindowInfo' : 'cef_window_info_t' + 'CefWindowInfo' : 'cef_window_info_t', + 'CefPopupFeatures' : 'cef_popup_features_t' } if value in structuretypes.keys(): return {