Expose popup window feature information with CefPopupFeatures argument to CefHandler::HandleBeforeCreated (issue #135).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@139 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2010-11-16 16:45:49 +00:00
parent 239a283e02
commit 6ad535823a
12 changed files with 204 additions and 40 deletions

View File

@ -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<CefBrowser> parentBrowser,
CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler>& 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<const cef_popup_features_t&>(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

View File

@ -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.

View File

@ -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

View File

@ -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> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
bool popup,
CefRefPtr<CefHandler> handler,
const std::wstring& url)
bool popup, CefRefPtr<CefHandler> handler, const std::wstring& url)
{
if(!_Context.get() || !CefThread::CurrentlyOn(CefThread::UI))
return NULL;
@ -528,7 +526,7 @@ CefRefPtr<CefBrowser> 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> CefBrowserImpl::UIT_CreatePopupWindow(const std::wstring& url)
CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(
const std::wstring& url, const CefPopupFeatures& features)
{
REQUIRE_UIT();
@ -807,8 +806,8 @@ CefRefPtr<CefBrowserImpl> 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;
}

View File

@ -188,7 +188,8 @@ public:
bool ignoreCahce);
void UIT_SetFocus(WebWidgetHost* host, bool enable);
CefRefPtr<CefBrowserImpl> UIT_CreatePopupWindow(const std::wstring& url);
CefRefPtr<CefBrowserImpl> UIT_CreatePopupWindow(const std::wstring& url,
const CefPopupFeatures& features);
WebKit::WebWidget* UIT_CreatePopupWidget();
void UIT_ClosePopupWidget();

View File

@ -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<int>(webKitFeatures.x);
features.xSet = webKitFeatures.xSet;
features.y = static_cast<int>(webKitFeatures.y);
features.ySet = webKitFeatures.ySet;
features.width = static_cast<int>(webKitFeatures.width);
features.widthSet = webKitFeatures.widthSet;
features.height = static_cast<int>(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<CefBrowserImpl> 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<CefHandler> 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(

View File

@ -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<CefHandler> 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);

View File

@ -24,7 +24,8 @@
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeCreated(
CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler>& handler, std::wstring& url)
CefRefPtr<CefHandler>& 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.

View File

@ -33,7 +33,7 @@ public:
// CefHandler methods
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& windowInfo, bool popup, CefRefPtr<CefHandler>& handler,
std::wstring& url);
std::wstring& url, const CefPopupFeatures& popupFeatures);
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser);
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, const std::wstring& url);

View File

@ -43,7 +43,8 @@ public:
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& createInfo, bool popup,
CefRefPtr<CefHandler>& handler,
std::wstring& url)
std::wstring& url,
const CefPopupFeatures& popupFeatures)
{
return RV_CONTINUE;
}

View File

@ -27,7 +27,8 @@ public:
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& createInfo, bool popup,
CefRefPtr<CefHandler>& handler,
std::wstring& url)
std::wstring& url,
const CefPopupFeatures& popupFeatures)
{
return RV_CONTINUE;
}

View File

@ -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 {