Improve thread safety and documentation and add support for thread-specific APIs (issue #175).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@174 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2011-01-29 01:42:59 +00:00
parent c89349cf5a
commit 7f1694fb68
20 changed files with 1207 additions and 1128 deletions

View File

@@ -29,7 +29,7 @@ BrowserDevToolsClient::BrowserDevToolsClient(CefBrowserImpl* browser,
: ALLOW_THIS_IN_INITIALIZER_LIST(call_method_factory_(this)),
browser_(browser),
dev_tools_agent_(agent),
web_view_(browser->GetWebView()) {
web_view_(browser->UIT_GetWebView()) {
web_tools_frontend_.reset(WebDevToolsFrontend::create(web_view_, this,
WebString::fromUTF8("en-US")));
dev_tools_agent_->attach(this);

View File

@@ -44,12 +44,95 @@ using WebKit::WebURL;
using WebKit::WebURLRequest;
using WebKit::WebView;
namespace {
class CreateBrowserHelper
{
public:
CreateBrowserHelper(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler, const CefString& url)
: window_info_(windowInfo), popup_(popup),
handler_(handler), url_(url) {}
CefWindowInfo window_info_;
bool popup_;
CefRefPtr<CefHandler> handler_;
CefString url_;
};
void UIT_CreateBrowserWithHelper(CreateBrowserHelper* helper)
{
CefBrowser::CreateBrowserSync(helper->window_info_, helper->popup_,
helper->handler_, helper->url_);
delete helper;
}
} // namespace
// static
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler,
const CefString& url)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED();
return false;
}
// Create the browser on the UI thread.
CreateBrowserHelper* helper =
new CreateBrowserHelper(windowInfo, popup, handler, url);
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableFunction(
UIT_CreateBrowserWithHelper, helper));
return true;
}
// static
CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
bool popup, CefRefPtr<CefHandler> handler, const CefString& url)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED();
return NULL;
}
// Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return NULL;
}
CefString newUrl = url;
CefRefPtr<CefBrowser> alternateBrowser;
CefBrowserSettings settings(_Context->browser_defaults());
if(handler.get())
{
// Give the handler an opportunity to modify window attributes, handler,
// or cancel the window creation.
CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo,
popup, CefPopupFeatures(), handler, newUrl, settings);
if(rv == RV_HANDLED)
return false;
}
CefRefPtr<CefBrowser> browser(
new CefBrowserImpl(windowInfo, settings, popup, handler));
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser(newUrl);
return browser;
}
CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
const CefBrowserSettings& settings, bool popup,
CefRefPtr<CefHandler> handler)
: window_info_(windowInfo), settings_(settings), is_popup_(popup),
is_modal_(false), handler_(handler), webviewhost_(NULL), popuphost_(NULL),
frame_main_(NULL), unique_id_(0)
zoom_level_(0.0), can_go_back_(false), can_go_forward_(false),
main_frame_(NULL), unique_id_(0)
{
delegate_.reset(new BrowserWebViewDelegate(this));
popup_delegate_.reset(new BrowserWebViewDelegate(this));
@@ -62,69 +145,12 @@ CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
}
}
bool CefBrowserImpl::CanGoBack()
{
if(!CefThread::CurrentlyOn(CefThread::UI))
{
// We need to send the request to the UI thread and wait for the result
// Event that will be used to signal that data is available. Start
// in non-signaled mode so that the event will block.
base::WaitableEvent event(false, false);
bool retVal = true;
// Request the data from the UI thread
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_CanGoBackNotify, &retVal, &event));
// Wait for the UI thread callback to tell us that the data is available
event.Wait();
return retVal;
}
else
{
// Call the method directly
return UIT_CanGoBack();
}
}
void CefBrowserImpl::GoBack()
{
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_BACK));
}
bool CefBrowserImpl::CanGoForward()
{
if(!CefThread::CurrentlyOn(CefThread::UI))
{
// We need to send the request to the UI thread and wait for the result
// Event that will be used to signal that data is available. Start
// in non-signaled mode so that the event will block.
base::WaitableEvent event(false, false);
bool retVal = true;
// Request the data from the UI thread
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_CanGoForwardNotify, &retVal, &event));
// Wait for the UI thread callback to tell us that the data is available
event.Wait();
return retVal;
}
else
{
// Call the method directly
return UIT_CanGoForward();
}
}
void CefBrowserImpl::GoForward()
{
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
@@ -151,55 +177,53 @@ void CefBrowserImpl::StopLoad()
void CefBrowserImpl::SetFocus(bool enable)
{
if (CefThread::CurrentlyOn(CefThread::UI))
{
UIT_SetFocus(GetWebViewHost(), enable);
}
else
{
if (CefThread::CurrentlyOn(CefThread::UI)) {
UIT_SetFocus(UIT_GetWebViewHost(), enable);
} else {
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_SetFocus, GetWebViewHost(), enable));
&CefBrowserImpl::UIT_SetFocus, UIT_GetWebViewHost(), enable));
}
}
bool CefBrowserImpl::IsPopup()
{
Lock();
bool popup = is_popup_;
Unlock();
return popup;
}
CefRefPtr<CefHandler> CefBrowserImpl::GetHandler()
{
return handler_;
}
CefRefPtr<CefFrame> CefBrowserImpl::GetMainFrame()
{
return GetWebView() ? GetCefFrame(GetWebView()->mainFrame()) : NULL;
}
CefRefPtr<CefFrame> CefBrowserImpl::GetFocusedFrame()
{
return GetWebView() ? GetCefFrame(GetWebView()->focusedFrame()) : NULL;
// Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return NULL;
}
WebView* view = UIT_GetWebView();
return view ? UIT_GetCefFrame(view->focusedFrame()) : NULL;
}
CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(const CefString& name)
{
WebView* view = GetWebView();
// Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return NULL;
}
WebView* view = UIT_GetWebView();
if (!view)
return NULL;
WebFrame* frame = view->findFrameByName(string16(name));
if(frame)
return GetCefFrame(frame);
return UIT_GetCefFrame(frame);
return NULL;
}
void CefBrowserImpl::GetFrameNames(std::vector<CefString>& names)
{
WebView* view = GetWebView();
// Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return;
}
WebView* view = UIT_GetWebView();
if (!view)
return;
@@ -234,6 +258,12 @@ void CefBrowserImpl::StopFinding(bool clearSelection)
&CefBrowserImpl::UIT_StopFinding, clearSelection));
}
void CefBrowserImpl::SetZoomLevel(double zoomLevel)
{
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_SetZoomLevel, zoomLevel));
}
void CefBrowserImpl::ShowDevTools()
{
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
@@ -246,63 +276,6 @@ void CefBrowserImpl::CloseDevTools()
&CefBrowserImpl::UIT_CloseDevTools));
}
CefRefPtr<CefFrame> CefBrowserImpl::GetCefFrame(WebFrame* frame)
{
CefRefPtr<CefFrame> cef_frame;
Lock();
WebView *view = GetWebView();
if(view) {
if(frame == view->mainFrame()) {
// Use or create the single main frame reference.
if(frame_main_ == NULL)
frame_main_ = new CefFrameImpl(this, CefString());
cef_frame = frame_main_;
} else {
// Locate or create the appropriate named reference.
CefString name = string16(frame->name());
DCHECK(!name.empty());
FrameMap::const_iterator it = frames_.find(name);
if(it != frames_.end())
cef_frame = it->second;
else {
cef_frame = new CefFrameImpl(this, name);
frames_.insert(std::make_pair(name, cef_frame.get()));
}
}
}
Unlock();
return cef_frame;
}
void CefBrowserImpl::RemoveCefFrame(const CefString& name)
{
Lock();
if(name.empty())
frame_main_ = NULL;
else {
FrameMap::iterator it = frames_.find(name);
if(it != frames_.end())
frames_.erase(it);
}
Unlock();
}
WebFrame* CefBrowserImpl::GetWebFrame(CefRefPtr<CefFrame> frame)
{
WebView* view = GetWebView();
if (!view)
return NULL;
CefString name = frame->GetName();
if(name.empty())
return view ->mainFrame();
return view ->findFrameByName(string16(name));
}
void CefBrowserImpl::Undo(CefRefPtr<CefFrame> frame)
{
frame->AddRef();
@@ -369,70 +342,32 @@ void CefBrowserImpl::ViewSource(CefRefPtr<CefFrame> frame)
CefString CefBrowserImpl::GetSource(CefRefPtr<CefFrame> frame)
{
if(!CefThread::CurrentlyOn(CefThread::UI))
{
// We need to send the request to the UI thread and wait for the result
// Event that will be used to signal that data is available. Start
// in non-signaled mode so that the event will block.
base::WaitableEvent event(false, false);
CefRefPtr<CefStreamWriter> stream(new CefBytesWriter(BUFFER_SIZE));
// Request the data from the UI thread
frame->AddRef();
stream->AddRef();
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_GetDocumentStringNotify, frame.get(), stream.get(),
&event));
// Wait for the UI thread callback to tell us that the data is available
event.Wait();
return static_cast<CefBytesWriter*>(stream.get())->GetDataString();
}
else
{
// Retrieve the document string directly
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
return string16(web_frame->contentAsMarkup());
// Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return CefString();
}
// Retrieve the document string directly
WebKit::WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame)
return string16(web_frame->contentAsMarkup());
return CefString();
}
CefString CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame)
{
if(!CefThread::CurrentlyOn(CefThread::UI))
{
// We need to send the request to the UI thread and wait for the result
// Event that will be used to signal that data is available. Start
// in non-signaled mode so that the event will block.
base::WaitableEvent event(false, false);
CefRefPtr<CefStreamWriter> stream(new CefBytesWriter(BUFFER_SIZE));
// Request the data from the UI thread
frame->AddRef();
stream->AddRef();
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_GetDocumentTextNotify, frame.get(), stream.get(),
&event));
// Wait for the UI thread callback to tell us that the data is available
event.Wait();
return static_cast<CefBytesWriter*>(stream.get())->GetDataString();
}
else
{
// Retrieve the document text directly
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
return webkit_glue::DumpDocumentText(web_frame);
// Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return CefString();
}
// Retrieve the document text directly
WebKit::WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame)
return webkit_glue::DumpDocumentText(web_frame);
return CefString();
}
void CefBrowserImpl::LoadRequest(CefRefPtr<CefFrame> frame,
@@ -487,96 +422,107 @@ void CefBrowserImpl::ExecuteJavaScript(CefRefPtr<CefFrame> frame,
CefString CefBrowserImpl::GetURL(CefRefPtr<CefFrame> frame)
{
WebFrame* web_frame = GetWebFrame(frame);
// Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return CefString();
}
WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame)
return std::string(web_frame->url().spec());
return CefString();
}
double CefBrowserImpl::GetZoomLevel()
CefRefPtr<CefFrame> CefBrowserImpl::GetCefFrame(const CefString& name)
{
WebKit::WebFrame* web_frame = GetWebFrame(this->GetMainFrame());
CefRefPtr<CefFrame> cef_frame;
if(web_frame && web_frame->view())
return web_frame->view()->zoomLevel();
return 0.0;
}
void CefBrowserImpl::SetZoomLevel(double zoomLevel)
{
CefRefPtr<CefFrame> frame = this->GetMainFrame();
frame->AddRef();
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_SetZoomLevel, frame.get(), zoomLevel));
}
// static
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler,
const CefString& url)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED();
return false;
if(name.empty()) {
// Use the single main frame reference.
cef_frame = GetMainCefFrame();
} else {
// Locate or create the appropriate named reference.
AutoLock lock_scope(this);
FrameMap::const_iterator it = frames_.find(name);
if(it != frames_.end())
cef_frame = it->second;
else {
cef_frame = new CefFrameImpl(this, name);
frames_.insert(std::make_pair(name, cef_frame.get()));
}
}
CefString newUrl = url;
CefBrowserSettings settings(_Context->browser_defaults());
if(handler.get())
{
// Give the handler an opportunity to modify window attributes, handler,
// or cancel the window creation.
CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo,
popup, CefPopupFeatures(), handler, newUrl, settings);
if(rv == RV_HANDLED)
return false;
}
CefRefPtr<CefBrowserImpl> browser(
new CefBrowserImpl(windowInfo, settings, popup, handler));
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(browser.get(),
&CefBrowserImpl::UIT_CreateBrowser, newUrl));
return true;
return cef_frame;
}
// static
CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
bool popup, CefRefPtr<CefHandler> handler, const CefString& url)
void CefBrowserImpl::RemoveCefFrame(const CefString& name)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED();
AutoLock lock_scope(this);
if(name.empty()) {
// Clear the single main frame reference.
main_frame_ = NULL;
} else {
// Remove the appropriate named reference.
FrameMap::iterator it = frames_.find(name);
if(it != frames_.end())
frames_.erase(it);
}
}
CefRefPtr<CefFrame> CefBrowserImpl::GetMainCefFrame()
{
// Return the single main frame reference.
AutoLock lock_scope(this);
if(main_frame_ == NULL)
main_frame_ = new CefFrameImpl(this, CefString());
return main_frame_;
}
CefRefPtr<CefFrame> CefBrowserImpl::UIT_GetCefFrame(WebFrame* frame)
{
REQUIRE_UIT();
CefRefPtr<CefFrame> cef_frame;
WebView *view = UIT_GetWebView();
if(view) {
if(frame == view->mainFrame()) {
// Use the single main frame reference.
cef_frame = GetMainCefFrame();
} else {
// Locate or create the appropriate named reference.
CefString name = string16(frame->name());
DCHECK(!name.empty());
cef_frame = GetCefFrame(name);
}
}
return cef_frame;
}
WebFrame* CefBrowserImpl::UIT_GetMainWebFrame()
{
REQUIRE_UIT();
WebView* view = UIT_GetWebView();
if (view)
return view ->mainFrame();
return NULL;
}
WebFrame* CefBrowserImpl::UIT_GetWebFrame(CefRefPtr<CefFrame> frame)
{
REQUIRE_UIT();
WebView* view = UIT_GetWebView();
if (!view)
return NULL;
}
// Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return NULL;
}
CefString newUrl = url;
CefRefPtr<CefBrowser> alternateBrowser;
CefBrowserSettings settings(_Context->browser_defaults());
if(handler.get())
{
// Give the handler an opportunity to modify window attributes, handler,
// or cancel the window creation.
CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo,
popup, CefPopupFeatures(), handler, newUrl, settings);
if(rv == RV_HANDLED)
return false;
}
CefRefPtr<CefBrowser> browser(
new CefBrowserImpl(windowInfo, settings, popup, handler));
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser(newUrl);
return browser;
CefString name = frame->GetName();
if(name.empty())
return view ->mainFrame();
return view ->findFrameByName(string16(name));
}
void CefBrowserImpl::UIT_DestroyBrowser()
@@ -585,7 +531,7 @@ void CefBrowserImpl::UIT_DestroyBrowser()
// Notify the handler that the window is about to be closed.
handler_->HandleBeforeWindowClose(this);
}
GetWebViewDelegate()->RevokeDragDrop();
UIT_GetWebViewDelegate()->RevokeDragDrop();
if (dev_tools_agent_.get()) {
BrowserDevToolsClient* client = dev_tools_agent_->client();
@@ -594,7 +540,7 @@ void CefBrowserImpl::UIT_DestroyBrowser()
}
// Clean up anything associated with the WebViewHost widget.
GetWebViewHost()->webwidget()->close();
UIT_GetWebViewHost()->webwidget()->close();
webviewhost_.reset();
// Remove the reference added in UIT_CreateBrowser().
@@ -680,7 +626,7 @@ void CefBrowserImpl::UIT_LoadHTML(CefFrame* frame,
return;
}
WebFrame* web_frame = GetWebFrame(frame);
WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame)
web_frame->loadHTMLString(std::string(html), gurl);
@@ -717,7 +663,7 @@ void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefFrame* frame,
}
while(read > 0);
WebFrame* web_frame = GetWebFrame(frame);
WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame)
web_frame->loadHTMLString(ss.str(), gurl);
@@ -732,7 +678,7 @@ void CefBrowserImpl::UIT_ExecuteJavaScript(CefFrame* frame,
{
REQUIRE_UIT();
WebFrame* web_frame = GetWebFrame(frame);
WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame) {
web_frame->executeScript(WebScriptSource(string16(js_code),
WebURL(GURL(std::string(script_url))), start_line));
@@ -759,7 +705,7 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
{
REQUIRE_UIT();
WebView* view = GetWebView();
WebView* view = UIT_GetWebView();
if (!view)
return false;
@@ -830,7 +776,7 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
// thread for additional details:
// http://groups.google.com/group/chromium-dev/browse_thread/thread/42bcd31b59e3a168
view->setFocusedFrame(frame);
UIT_SetFocus(GetWebViewHost(), true);
UIT_SetFocus(UIT_GetWebViewHost(), true);
}
return true;
@@ -886,7 +832,7 @@ void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
WebFrame* web_frame = NULL;
if(frame)
web_frame = GetWebFrame(frame);
web_frame = UIT_GetWebFrame(frame);
switch(menuId)
{
@@ -903,8 +849,8 @@ void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
UIT_Reload(true);
break;
case MENU_ID_NAV_STOP:
if (GetWebView())
GetWebView()->mainFrame()->stopLoading();
if (UIT_GetWebView())
UIT_GetWebView()->mainFrame()->stopLoading();
break;
case MENU_ID_UNDO:
if(web_frame)
@@ -948,76 +894,10 @@ void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
frame->Release();
}
void CefBrowserImpl::UIT_GetDocumentStringNotify(CefFrame* frame,
CefStreamWriter* writer,
base::WaitableEvent* event)
{
REQUIRE_UIT();
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
// Retrieve the document string
std::string markup = web_frame->contentAsMarkup().utf8();
// Write the document string to the stream
writer->Write(markup.c_str(), markup.size(), 1);
}
// Notify the calling thread that the data is now available
event->Signal();
writer->Release();
frame->Release();
}
void CefBrowserImpl::UIT_GetDocumentTextNotify(CefFrame* frame,
CefStreamWriter* writer,
base::WaitableEvent* event)
{
REQUIRE_UIT();
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
// Retrieve the document string
string16 wstr = webkit_glue::DumpDocumentText(web_frame);
std::string str;
UTF16ToUTF8(wstr.c_str(), wstr.length(), &str);
// Write the document string to the stream
writer->Write(str.c_str(), str.size(), 1);
}
// Notify the calling thread that the data is now available
event->Signal();
writer->Release();
frame->Release();
}
void CefBrowserImpl::UIT_CanGoBackNotify(bool *retVal,
base::WaitableEvent* event)
{
REQUIRE_UIT();
*retVal = UIT_CanGoBack();
// Notify the calling thread that the data is now available
event->Signal();
}
void CefBrowserImpl::UIT_CanGoForwardNotify(bool *retVal,
base::WaitableEvent* event)
{
REQUIRE_UIT();
*retVal = UIT_CanGoForward();
// Notify the calling thread that the data is now available
event->Signal();
}
void CefBrowserImpl::UIT_Find(int identifier, const CefString& search_text,
const WebKit::WebFindOptions& options)
{
WebView* view = GetWebView();
WebView* view = UIT_GetWebView();
if (!view)
return;
@@ -1140,7 +1020,7 @@ void CefBrowserImpl::UIT_Find(int identifier, const CefString& search_text,
void CefBrowserImpl::UIT_StopFinding(bool clear_selection)
{
WebView* view = GetWebView();
WebView* view = UIT_GetWebView();
if (!view)
return;
@@ -1169,8 +1049,7 @@ void CefBrowserImpl::UIT_NotifyFindStatus(int identifier, int count,
int active_match_ordinal,
bool final_update)
{
if(handler_.get())
{
if(handler_.get()) {
CefRect rect(selection_rect.x, selection_rect.y, selection_rect.width,
selection_rect.height);
handler_->HandleFindResult(this, identifier, count, rect,
@@ -1178,17 +1057,15 @@ void CefBrowserImpl::UIT_NotifyFindStatus(int identifier, int count,
}
}
void CefBrowserImpl::UIT_SetZoomLevel(CefFrame* frame, double zoomLevel)
void CefBrowserImpl::UIT_SetZoomLevel(double zoomLevel)
{
REQUIRE_UIT();
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame && web_frame->view()) {
WebKit::WebFrame* web_frame = UIT_GetMainWebFrame();
if(web_frame) {
web_frame->view()->setZoomLevel(false, zoomLevel);
ZoomMap::GetInstance()->set(web_frame->url(), zoomLevel);
set_zoom_level(zoomLevel);
}
frame->Release();
}
void CefBrowserImpl::UIT_ShowDevTools()
@@ -1209,7 +1086,7 @@ void CefBrowserImpl::UIT_ShowDevTools()
CefPopupFeatures features;
CefRefPtr<CefBrowserImpl> browser =
UIT_CreatePopupWindow(devtools_path.value(), features);
browser->CreateDevToolsClient(dev_tools_agent_.get());
browser->UIT_CreateDevToolsClient(dev_tools_agent_.get());
browser->UIT_Show(WebKit::WebNavigationPolicyNewWindow);
} else {
// Give focus to the existing inspector window.
@@ -1217,7 +1094,38 @@ void CefBrowserImpl::UIT_ShowDevTools()
}
}
void CefBrowserImpl::CreateDevToolsClient(BrowserDevToolsAgent *agent)
void CefBrowserImpl::set_zoom_level(double zoomLevel)
{
AutoLock lock_scope(this);
zoom_level_ = zoomLevel;
}
double CefBrowserImpl::zoom_level()
{
AutoLock lock_scope(this);
return zoom_level_;
}
void CefBrowserImpl::set_nav_state(bool can_go_back, bool can_go_forward)
{
AutoLock lock_scope(this);
can_go_back_ = can_go_back;
can_go_forward_ = can_go_forward;
}
bool CefBrowserImpl::can_go_back()
{
AutoLock lock_scope(this);
return can_go_back_;
}
bool CefBrowserImpl::can_go_forward()
{
AutoLock lock_scope(this);
return can_go_forward_;
}
void CefBrowserImpl::UIT_CreateDevToolsClient(BrowserDevToolsAgent *agent)
{
dev_tools_client_.reset(new BrowserDevToolsClient(this, agent));
}
@@ -1225,9 +1133,25 @@ void CefBrowserImpl::CreateDevToolsClient(BrowserDevToolsAgent *agent)
// CefFrameImpl
CefFrameImpl::CefFrameImpl(CefBrowserImpl* browser, const CefString& name)
: browser_(browser), name_(name)
{
}
CefFrameImpl::~CefFrameImpl()
{
browser_->RemoveCefFrame(name_);
}
bool CefFrameImpl::IsFocused()
{
return (browser_->GetWebView() &&
(browser_->GetWebFrame(this) ==
browser_->GetWebView()->focusedFrame()));
// Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return false;
}
return (browser_->UIT_GetWebView() &&
(browser_->UIT_GetWebFrame(this) ==
browser_->UIT_GetWebView()->focusedFrame()));
}

View File

@@ -47,41 +47,29 @@ public:
#endif
// CefBrowser methods
virtual bool CanGoBack();
virtual bool CanGoBack() { return can_go_back(); }
virtual void GoBack();
virtual bool CanGoForward();
virtual bool CanGoForward() { return can_go_forward(); }
virtual void GoForward();
virtual void Reload();
virtual void ReloadIgnoreCache();
virtual void StopLoad();
virtual void SetFocus(bool enable);
virtual CefWindowHandle GetWindowHandle();
virtual bool IsPopup();
virtual CefRefPtr<CefHandler> GetHandler();
virtual CefRefPtr<CefFrame> GetMainFrame();
virtual bool IsPopup() { return is_popup(); }
virtual CefRefPtr<CefHandler> GetHandler() { return handler_; }
virtual CefRefPtr<CefFrame> GetMainFrame() { return GetMainCefFrame(); }
virtual CefRefPtr<CefFrame> GetFocusedFrame();
virtual CefRefPtr<CefFrame> GetFrame(const CefString& name);
virtual void GetFrameNames(std::vector<CefString>& names);
virtual void Find(int identifier, const CefString& searchText,
bool forward, bool matchCase, bool findNext);
virtual void StopFinding(bool clearSelection);
virtual double GetZoomLevel();
virtual double GetZoomLevel() { return zoom_level(); }
virtual void SetZoomLevel(double zoomLevel);
virtual void ShowDevTools();
virtual void CloseDevTools();
// CefFrames are light-weight objects managed by the browser and loosely
// coupled to a WebFrame object by name. If a CefFrame object does not
// already exist for the specified WebFrame one will be created. There is no
// guarantee that the same CefFrame object will be returned across different
// calls to this function.
CefRefPtr<CefFrame> GetCefFrame(WebKit::WebFrame* frame);
void RemoveCefFrame(const CefString& name);
// Return the WebFrame object associated with the specified CefFrame. This
// may return NULL if no WebFrame with the CefFrame's name exists.
WebKit::WebFrame* GetWebFrame(CefRefPtr<CefFrame> frame);
// Frame-related methods
void Undo(CefRefPtr<CefFrame> frame);
void Redo(CefRefPtr<CefFrame> frame);
@@ -110,36 +98,62 @@ public:
int startLine);
CefString GetURL(CefRefPtr<CefFrame> frame);
WebKit::WebView* GetWebView() const {
return webviewhost_.get() ? webviewhost_->webview() : NULL;
}
WebViewHost* GetWebViewHost() const {
return webviewhost_.get();
}
BrowserWebViewDelegate* GetWebViewDelegate() const {
return delegate_.get();
}
gfx::NativeView GetWebViewWndHandle() const {
return webviewhost_->view_handle();
}
WebKit::WebWidget* GetPopup() const {
return popuphost_ ? popuphost_->webwidget() : NULL;
}
WebWidgetHost* GetPopupHost() const {
return popuphost_;
}
BrowserWebViewDelegate* GetPopupDelegate() const {
return popup_delegate_.get();
}
gfx::NativeView GetPopupWndHandle() const {
return popuphost_->view_handle();
}
gfx::NativeWindow GetMainWndHandle() const;
// CefFrames are light-weight objects managed by the browser and loosely
// coupled to a WebFrame object by name. If a CefFrame object does not
// already exist for the specified name one will be created. There is no
// guarantee that the same CefFrame object will be returned across different
// calls to this function.
CefRefPtr<CefFrame> GetCefFrame(const CefString& name);
void RemoveCefFrame(const CefString& name);
CefRefPtr<CefFrame> GetMainCefFrame();
////////////////////////////////////////////////////////////
// ALL UIT_* METHODS MUST ONLY BE CALLED ON THE UI THREAD //
////////////////////////////////////////////////////////////
CefRefPtr<CefFrame> UIT_GetCefFrame(WebKit::WebFrame* frame);
// Return the main WebFrame object.
WebKit::WebFrame* UIT_GetMainWebFrame();
// Return the WebFrame object associated with the specified CefFrame. This
// may return NULL if no WebFrame with the CefFrame's name exists.
WebKit::WebFrame* UIT_GetWebFrame(CefRefPtr<CefFrame> frame);
WebKit::WebView* UIT_GetWebView() const {
REQUIRE_UIT();
return webviewhost_.get() ? webviewhost_->webview() : NULL;
}
WebViewHost* UIT_GetWebViewHost() const {
REQUIRE_UIT();
return webviewhost_.get();
}
BrowserWebViewDelegate* UIT_GetWebViewDelegate() const {
REQUIRE_UIT();
return delegate_.get();
}
gfx::NativeView UIT_GetWebViewWndHandle() const {
REQUIRE_UIT();
return webviewhost_->view_handle();
}
WebKit::WebWidget* UIT_GetPopup() const {
REQUIRE_UIT();
return popuphost_ ? popuphost_->webwidget() : NULL;
}
WebWidgetHost* UIT_GetPopupHost() const {
REQUIRE_UIT();
return popuphost_;
}
BrowserWebViewDelegate* UIT_GetPopupDelegate() const {
REQUIRE_UIT();
return popup_delegate_.get();
}
gfx::NativeView UIT_GetPopupWndHandle() const {
REQUIRE_UIT();
return popuphost_->view_handle();
}
gfx::NativeWindow UIT_GetMainWndHandle() const;
BrowserNavigationController* UIT_GetNavigationController() {
REQUIRE_UIT();
return nav_controller_.get();
@@ -157,14 +171,14 @@ public:
is_modal_ = val;
}
void UIT_SetTitle(const CefString& title) {
REQUIRE_UIT();
title_ = title;
}
CefString UIT_GetTitle() {
REQUIRE_UIT();
return title_;
}
void UIT_SetTitle(const CefString& title) {
REQUIRE_UIT();
title_ = title;
}
void UIT_CreateBrowser(const CefString& url);
void UIT_DestroyBrowser();
@@ -209,13 +223,6 @@ public:
// Save the document HTML to a temporary file and open in the default viewing
// application
bool UIT_ViewDocumentString(WebKit::WebFrame *frame);
void UIT_GetDocumentStringNotify(CefFrame* frame,
CefStreamWriter* writer,
base::WaitableEvent* event);
void UIT_GetDocumentTextNotify(CefFrame* frame, CefStreamWriter* writer,
base::WaitableEvent* event);
void UIT_CanGoBackNotify(bool *retVal, base::WaitableEvent* event);
void UIT_CanGoForwardNotify(bool *retVal, base::WaitableEvent* event);
bool UIT_CanGoBack() { return !nav_controller_->IsAtStart(); }
bool UIT_CanGoForward() { return !nav_controller_->IsAtEnd(); }
@@ -235,17 +242,26 @@ public:
void UIT_NotifyFindStatus(int identifier, int count,
const WebKit::WebRect& selection_rect,
int active_match_ordinal, bool final_update);
void UIT_SetZoomLevel(CefFrame* frame, double zoomLevel);
void UIT_SetZoomLevel(double zoomLevel);
void UIT_ShowDevTools();
void UIT_CloseDevTools();
static bool ImplementsThreadSafeReferenceCounting() { return true; }
// These variables are read-only.
const CefBrowserSettings& settings() const { return settings_; }
const FilePath& file_system_root() const { return file_system_root_.path(); }
bool is_popup() { return is_popup_; }
// These variables may be read/written from multiple threads.
void set_zoom_level(double zoomLevel);
double zoom_level();
void set_nav_state(bool can_go_back, bool can_go_forward);
bool can_go_back();
bool can_go_forward();
static bool ImplementsThreadSafeReferenceCounting() { return true; }
protected:
void CreateDevToolsClient(BrowserDevToolsAgent* agent);
void UIT_CreateDevToolsClient(BrowserDevToolsAgent* agent);
protected:
CefWindowInfo window_info_;
@@ -264,6 +280,10 @@ protected:
CefString title_;
double zoom_level_;
bool can_go_back_;
bool can_go_forward_;
#if defined(OS_WIN)
// Context object used to manage printing.
printing::PrintingContext print_context_;
@@ -271,7 +291,7 @@ protected:
typedef std::map<CefString, CefFrame*> FrameMap;
FrameMap frames_;
CefFrame* frame_main_;
CefFrame* main_frame_;
// Unique browser ID assigned by the context.
int unique_id_;
@@ -285,9 +305,8 @@ protected:
class CefFrameImpl : public CefThreadSafeBase<CefFrame>
{
public:
CefFrameImpl(CefBrowserImpl* browser, const CefString& name)
: browser_(browser), name_(name) {}
virtual ~CefFrameImpl() { browser_->RemoveCefFrame(name_); }
CefFrameImpl(CefBrowserImpl* browser, const CefString& name);
virtual ~CefFrameImpl();
// CefFrame methods
virtual void Undo() { browser_->Undo(this); }

View File

@@ -20,13 +20,12 @@ using WebKit::WebSize;
CefWindowHandle CefBrowserImpl::GetWindowHandle()
{
Lock();
CefWindowHandle handle = window_info_.m_Widget;
Unlock();
return handle;
AutoLock lock_scope(this);
return window_info_.m_Widget;
}
gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const {
gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() const {
REQUIRE_UIT();
GtkWidget* toplevel = gtk_widget_get_ancestor(window_info_.m_Widget,
GTK_TYPE_WINDOW);
return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL;
@@ -35,7 +34,8 @@ gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const {
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
{
REQUIRE_UIT();
Lock();
// Add a reference that will be released in UIT_DestroyBrowser().
AddRef();
@@ -58,7 +58,9 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
dev_tools_agent_->SetWebView(webviewhost_->webview());
window_info_.m_Widget = webviewhost_->view_handle();
Unlock();
if(handler_.get()) {
// Notify the handler that we're done creating the new window
handler_->HandleAfterCreated(this);

View File

@@ -21,20 +21,20 @@ using WebKit::WebSize;
CefWindowHandle CefBrowserImpl::GetWindowHandle()
{
Lock();
CefWindowHandle handle = window_info_.m_View;
Unlock();
return handle;
AutoLock lock_scope(this);
return window_info_.m_View;
}
gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const {
gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() const {
REQUIRE_UIT();
return (NSWindow*)window_info_.m_View;
}
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
{
REQUIRE_UIT();
Lock();
// Add a reference that will be released in UIT_DestroyBrowser().
AddRef();
@@ -63,7 +63,9 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle();
browserView.browser = this;
window_info_.m_View = (void*)browserView;
Unlock();
if(handler_.get()) {
// Notify the handler that we're done creating the new window
handler_->HandleAfterCreated(this);

View File

@@ -57,23 +57,23 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
return 0;
case WM_SIZE:
if (browser && browser->GetWebView()) {
if (browser && browser->UIT_GetWebView()) {
// resize the web view window to the full size of the browser window
RECT rc;
GetClientRect(browser->GetMainWndHandle(), &rc);
MoveWindow(browser->GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom,
GetClientRect(browser->UIT_GetMainWndHandle(), &rc);
MoveWindow(browser->UIT_GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom,
TRUE);
}
return 0;
case WM_SETFOCUS:
if (browser && browser->GetWebView())
browser->GetWebView()->setFocus(true);
if (browser && browser->UIT_GetWebView())
browser->UIT_GetWebView()->setFocus(true);
return 0;
case WM_KILLFOCUS:
if (browser && browser->GetWebView())
browser->GetWebView()->setFocus(false);
if (browser && browser->UIT_GetWebView())
browser->UIT_GetWebView()->setFocus(false);
return 0;
case WM_ERASEBKGND:
@@ -85,19 +85,19 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
CefWindowHandle CefBrowserImpl::GetWindowHandle()
{
Lock();
CefWindowHandle handle = window_info_.m_hWnd;
Unlock();
return handle;
AutoLock lock_scope(this);
return window_info_.m_hWnd;
}
gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const {
gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() const {
REQUIRE_UIT();
return window_info_.m_hWnd;
}
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
{
REQUIRE_UIT();
Lock();
std::wstring windowName(CefString(&window_info_.m_windowName));
@@ -136,10 +136,12 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
if (!settings_.drag_drop_disabled)
delegate_->RegisterDragDrop();
Unlock();
// Size the web view window to the browser window
RECT cr;
GetClientRect(window_info_.m_hWnd, &cr);
SetWindowPos(GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
SetWindowPos(UIT_GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
cr.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
if(handler_.get()) {
@@ -172,7 +174,7 @@ WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget()
DCHECK(!popuphost_);
popuphost_ = WebWidgetHost::Create(NULL, popup_delegate_.get());
ShowWindow(GetPopupWndHandle(), SW_SHOW);
ShowWindow(UIT_GetPopupWndHandle(), SW_SHOW);
return popuphost_->webwidget();
}
@@ -181,7 +183,7 @@ void CefBrowserImpl::UIT_ClosePopupWidget()
{
REQUIRE_UIT();
PostMessage(GetPopupWndHandle(), WM_CLOSE, 0, 0);
PostMessage(UIT_GetPopupWndHandle(), WM_CLOSE, 0, 0);
popuphost_ = NULL;
}
@@ -225,7 +227,7 @@ bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame *frame)
std::string markup = frame->contentAsMarkup().utf8();
WriteTextToFile(markup, szTempName);
int errorCode = (int)ShellExecute(GetMainWndHandle(), L"open", szTempName,
int errorCode = (int)ShellExecute(UIT_GetMainWndHandle(), L"open", szTempName,
NULL, NULL, SW_SHOWNORMAL);
if(errorCode <= 32)
return false;
@@ -322,7 +324,7 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
// allow the handler to format print header and/or footer
CefHandler::RetVal rv = handler_->HandlePrintHeaderFooter(this,
GetCefFrame(frame), printInfo, url, title, page_number+1, total_pages,
UIT_GetCefFrame(frame), printInfo, url, title, page_number+1, total_pages,
topLeft, topCenter, topRight, bottomLeft, bottomCenter, bottomRight);
if(rv != RV_HANDLED) {
@@ -408,7 +410,7 @@ void CefBrowserImpl::UIT_PrintPages(WebKit::WebFrame* frame) {
}
if(print_context_.AskUserForSettings(
GetMainWndHandle(), UIT_GetPagesCount(frame), false)
UIT_GetMainWndHandle(), UIT_GetPagesCount(frame), false)
!= printing::PrintingContext::OK)
return;
@@ -497,5 +499,5 @@ void CefBrowserImpl::UIT_CloseDevTools()
BrowserDevToolsClient* client = dev_tools_agent_->client();
if (client)
PostMessage(client->browser()->GetMainWndHandle(), WM_CLOSE, 0, 0);
PostMessage(client->browser()->UIT_GetMainWndHandle(), WM_CLOSE, 0, 0);
}

View File

@@ -172,7 +172,7 @@ WebView* BrowserWebViewDelegate::createView(WebFrame* creator,
TranslatePopupFeatures(features, cefFeatures);
CefRefPtr<CefBrowserImpl> browser =
browser_->UIT_CreatePopupWindow(url, cefFeatures);
return browser.get() ? browser->GetWebView() : NULL;
return browser.get() ? browser->UIT_GetWebView() : NULL;
}
WebWidget* BrowserWebViewDelegate::createPopupMenu(WebPopupType popup_type) {
@@ -215,8 +215,11 @@ void BrowserWebViewDelegate::didAddMessageToConsole(
}
void BrowserWebViewDelegate::printPage(WebFrame* frame) {
if (!frame)
frame = browser_->GetWebView() ? browser_->GetWebView()->mainFrame() : NULL;
if (!frame) {
WebView* view = browser_->UIT_GetWebView();
if (view)
frame = view->mainFrame();
}
if (frame)
browser_->UIT_PrintPages(frame);
}
@@ -299,8 +302,10 @@ bool BrowserWebViewDelegate::handleCurrentKeyboardEvent() {
if (edit_command_name_.empty())
return false;
WebFrame* frame = browser_->GetWebView() ?
browser_->GetWebView()->focusedFrame() : NULL;
WebView* view = browser_->UIT_GetWebView();
WebFrame* frame = NULL;
if (view)
frame = view->focusedFrame();
if (!frame)
return false;
@@ -335,7 +340,7 @@ void BrowserWebViewDelegate::runModalAlertDialog(
CefString messageStr = string16(message);
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
rv = handler->HandleJSAlert(browser_, browser_->GetCefFrame(frame),
rv = handler->HandleJSAlert(browser_, browser_->UIT_GetCefFrame(frame),
messageStr);
}
if(rv != RV_HANDLED)
@@ -349,7 +354,7 @@ bool BrowserWebViewDelegate::runModalConfirmDialog(
bool retval = false;
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
rv = handler->HandleJSConfirm(browser_, browser_->GetCefFrame(frame),
rv = handler->HandleJSConfirm(browser_, browser_->UIT_GetCefFrame(frame),
messageStr, retval);
}
if(rv != RV_HANDLED)
@@ -370,7 +375,7 @@ bool BrowserWebViewDelegate::runModalPromptDialog(
bool retval = false;
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
rv = handler->HandleJSPrompt(browser_, browser_->GetCefFrame(frame),
rv = handler->HandleJSPrompt(browser_, browser_->UIT_GetCefFrame(frame),
messageStr, defaultValueStr, retval, actualValueStr);
}
if(rv != RV_HANDLED) {
@@ -426,8 +431,9 @@ void BrowserWebViewDelegate::startDragging(
//HRESULT res = DoDragDrop(drop_data.data_object, drag_delegate_.get(),
// ok_effect, &effect);
//DCHECK(DRAGDROP_S_DROP == res || DRAGDROP_S_CANCEL == res);
if (browser_->GetWebView())
browser_->GetWebView()->dragSourceSystemDragEnded();
WebView* view = browser_->UIT_GetWebView();
if (view)
view->dragSourceSystemDragEnded();
}
void BrowserWebViewDelegate::focusNext() {
@@ -591,7 +597,7 @@ WebNavigationPolicy BrowserWebViewDelegate::decidePolicyForNavigation(
// Notify the handler of a browse request
CefHandler::RetVal rv = handler->HandleBeforeBrowse(browser_,
browser_->GetCefFrame(frame), req, (CefHandler::NavType)type,
browser_->UIT_GetCefFrame(frame), req, (CefHandler::NavType)type,
is_redirect);
if(rv == RV_HANDLED)
return WebKit::WebNavigationPolicyIgnore;
@@ -673,7 +679,7 @@ void BrowserWebViewDelegate::didFailProvisionalLoad(
if(handler.get()) {
// give the handler an opportunity to generate a custom error message
rv = handler->HandleLoadError(browser_,
browser_->GetCefFrame(frame),
browser_->UIT_GetCefFrame(frame),
static_cast<CefHandler::ErrorCode>(error.reason),
std::string(failed_ds->request().url().spec().data()), errorStr);
}
@@ -724,18 +730,17 @@ void BrowserWebViewDelegate::didCommitProvisionalLoad(
if(handler.get()) {
// Notify the handler that loading has started.
handler->HandleLoadStart(browser_,
(frame == top_loading_frame_) ? NULL : browser_->GetCefFrame(frame),
(frame == top_loading_frame_) ? NULL : browser_->UIT_GetCefFrame(frame),
is_main_content_);
}
// Apply zoom settings only on top-level frames.
if(frame->parent() == NULL) {
// Restore the zoom value that we have for this URL, if any.
double zoomLevel;
if(ZoomMap::GetInstance()->get(frame->url(), zoomLevel))
frame->view()->setZoomLevel(false, zoomLevel);
else
frame->view()->setZoomLevel(false, 0.0);
double zoomLevel = 0.0;
ZoomMap::GetInstance()->get(frame->url(), zoomLevel);
frame->view()->setZoomLevel(false, zoomLevel);
browser_->set_zoom_level(zoomLevel);
}
}
@@ -749,7 +754,7 @@ void BrowserWebViewDelegate::didClearWindowObject(WebFrame* frame) {
v8::Context::Scope scope(context);
CefRefPtr<CefFrame> cframe(browser_->GetCefFrame(frame));
CefRefPtr<CefFrame> cframe(browser_->UIT_GetCefFrame(frame));
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(context->Global());
handler->HandleJSBinding(browser_, cframe, object);
}
@@ -869,15 +874,15 @@ void BrowserWebViewDelegate::RegisterDragDrop() {
#if defined(OS_WIN)
// TODO(port): add me once drag and drop works.
DCHECK(!drop_delegate_);
drop_delegate_ = new BrowserDropDelegate(browser_->GetWebViewWndHandle(),
browser_->GetWebView());
drop_delegate_ = new BrowserDropDelegate(browser_->UIT_GetWebViewWndHandle(),
browser_->UIT_GetWebView());
#endif
}
void BrowserWebViewDelegate::RevokeDragDrop() {
#if defined(OS_WIN)
if (drop_delegate_.get())
::RevokeDragDrop(browser_->GetWebViewWndHandle());
::RevokeDragDrop(browser_->UIT_GetWebViewWndHandle());
#endif
}
@@ -926,8 +931,8 @@ void BrowserWebViewDelegate::LocationChangeDone(WebFrame* frame) {
// Notify the handler that loading has ended.
int httpStatusCode = frame->dataSource()->response().httpStatusCode();
handler->HandleLoadEnd(browser_,
(is_top_frame) ? NULL : browser_->GetCefFrame(frame), is_main_content_,
httpStatusCode);
(is_top_frame) ? NULL : browser_->UIT_GetCefFrame(frame),
is_main_content_, httpStatusCode);
}
if (is_top_frame && is_main_content_)
@@ -935,10 +940,10 @@ void BrowserWebViewDelegate::LocationChangeDone(WebFrame* frame) {
}
WebWidgetHost* BrowserWebViewDelegate::GetWidgetHost() {
if (this == browser_->GetWebViewDelegate())
return browser_->GetWebViewHost();
if (this == browser_->GetPopupDelegate())
return browser_->GetPopupHost();
if (this == browser_->UIT_GetWebViewDelegate())
return browser_->UIT_GetWebViewHost();
if (this == browser_->UIT_GetPopupDelegate())
return browser_->UIT_GetPopupHost();
return NULL;
}
@@ -989,7 +994,8 @@ void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
if(handler.get()) {
// Notify the handler of an address change
std::string url = std::string(entry->GetURL().spec().c_str());
handler->HandleAddressChange(browser_, browser_->GetCefFrame(frame), url);
handler->HandleAddressChange(browser_, browser_->UIT_GetCefFrame(frame),
url);
}
}
@@ -997,7 +1003,10 @@ void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
if (!history_item.isNull())
entry->SetContentState(webkit_glue::HistoryItemToString(history_item));
browser_->UIT_GetNavigationController()->DidNavigateToEntry(entry.release());
BrowserNavigationController* controller =
browser_->UIT_GetNavigationController();
controller->DidNavigateToEntry(entry.release());
browser_->set_nav_state(!controller->IsAtStart(), !controller->IsAtEnd());
last_page_id_updated_ = std::max(last_page_id_updated_, page_id_);
}
@@ -1014,11 +1023,11 @@ void BrowserWebViewDelegate::UpdateSessionHistory(WebFrame* frame) {
if (!entry)
return;
if (!browser_->GetWebView())
WebView* view = browser_->UIT_GetWebView();
if (!view)
return;
const WebHistoryItem& history_item =
browser_->GetWebView()->mainFrame()->previousHistoryItem();
const WebHistoryItem& history_item = view->mainFrame()->previousHistoryItem();
if (history_item.isNull())
return;

View File

@@ -102,10 +102,10 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
}
void BrowserWebViewDelegate::closeWidgetSoon() {
if (this == browser_->GetWebViewDelegate()) {
if (this == browser_->UIT_GetWebViewDelegate()) {
MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(
&gtk_widget_destroy, GTK_WIDGET(browser_->GetMainWndHandle())));
} else if (this == browser_->GetPopupDelegate()) {
&gtk_widget_destroy, GTK_WIDGET(browser_->UIT_GetMainWndHandle())));
} else if (this == browser_->UIT_GetPopupDelegate()) {
browser_->UIT_ClosePopupWidget();
}
}
@@ -132,7 +132,7 @@ void BrowserWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) {
gdk_cursor = gfx::GetCursor(cursor_type);
}
cursor_type_ = cursor_type;
gdk_window_set_cursor(browser_->GetWebViewWndHandle()->window, gdk_cursor);
gdk_window_set_cursor(browser_->UIT_GetWebViewWndHandle()->window, gdk_cursor);
}
WebRect BrowserWebViewDelegate::windowRect() {
@@ -152,9 +152,9 @@ WebRect BrowserWebViewDelegate::windowRect() {
}
void BrowserWebViewDelegate::setWindowRect(const WebRect& rect) {
if (this == browser_->GetWebViewDelegate()) {
if (this == browser_->UIT_GetWebViewDelegate()) {
// TODO(port): Set the window rectangle.
} else if (this == browser_->GetPopupDelegate()) {
} else if (this == browser_->UIT_GetPopupDelegate()) {
WebWidgetHost* host = GetWidgetHost();
GtkWidget* drawing_area = host->view_handle();
GtkWidget* window =
@@ -198,7 +198,7 @@ webkit::npapi::WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
// TODO(evanm): we probably shouldn't be doing this mapping to X ids at
// this level.
GdkNativeWindow plugin_parent =
GDK_WINDOW_XWINDOW(browser_->GetWebViewHost()->view_handle()->window);
GDK_WINDOW_XWINDOW(browser_->UIT_GetWebViewHost()->view_handle()->window);
return webkit::npapi::WebPluginDelegateImpl::Create(path, mime_type,
plugin_parent);
@@ -206,12 +206,12 @@ webkit::npapi::WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
void BrowserWebViewDelegate::CreatedPluginWindow(
gfx::PluginWindowHandle id) {
browser_->GetWebViewHost()->CreatePluginContainer(id);
browser_->UIT_GetWebViewHost()->CreatePluginContainer(id);
}
void BrowserWebViewDelegate::WillDestroyPluginWindow(
gfx::PluginWindowHandle id) {
browser_->GetWebViewHost()->DestroyPluginContainer(id);
browser_->UIT_GetWebViewHost()->DestroyPluginContainer(id);
}
void BrowserWebViewDelegate::DidMovePlugin(

View File

@@ -42,7 +42,7 @@ void BrowserWebViewDelegate::showContextMenu(
void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
if (!popup_menu_info_.get())
return;
if (this != browser_->GetPopupDelegate())
if (this != browser_->UIT_GetPopupDelegate())
return;
// Display a HTML select menu.
@@ -59,7 +59,7 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
const WebRect& bounds = popup_bounds_;
// Set up the menu position.
NSView* web_view = browser_->GetWebViewWndHandle();
NSView* web_view = browser_->UIT_GetWebViewWndHandle();
NSRect view_rect = [web_view bounds];
int y_offset = bounds.y + bounds.height;
NSRect position = NSMakeRect(bounds.x, view_rect.size.height - y_offset,
@@ -71,15 +71,15 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
fontSize:font_size
rightAligned:right_aligned]);
[menu_runner runMenuInView:browser_->GetWebViewWndHandle()
[menu_runner runMenuInView:browser_->UIT_GetWebViewWndHandle()
withBounds:position
initialIndex:selected_index];
// Get the selected item and forward to WebKit. WebKit expects an input event
// (mouse down, keyboard activity) for this, so we calculate the proper
// position based on the selected index and provided bounds.
WebWidgetHost* popup = browser_->GetPopupHost();
int window_num = [browser_->GetMainWndHandle() windowNumber];
WebWidgetHost* popup = browser_->UIT_GetPopupHost();
int window_num = [browser_->UIT_GetMainWndHandle() windowNumber];
NSEvent* event =
webkit_glue::EventWithMenuAction([menu_runner menuItemWasChosen],
window_num, item_height,
@@ -98,10 +98,10 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
}
void BrowserWebViewDelegate::closeWidgetSoon() {
if (this == browser_->GetWebViewDelegate()) {
NSWindow *win = browser_->GetMainWndHandle();
if (this == browser_->UIT_GetWebViewDelegate()) {
NSWindow *win = browser_->UIT_GetMainWndHandle();
[win performSelector:@selector(performClose:) withObject:nil afterDelay:0];
} else if (this == browser_->GetPopupDelegate()) {
} else if (this == browser_->UIT_GetPopupDelegate()) {
browser_->UIT_ClosePopupWidget();
}
}
@@ -121,9 +121,9 @@ WebRect BrowserWebViewDelegate::windowRect() {
}
void BrowserWebViewDelegate::setWindowRect(const WebRect& rect) {
if (this == browser_->GetWebViewDelegate()) {
if (this == browser_->UIT_GetWebViewDelegate()) {
// TODO(port): Set the window rectangle.
} else if (this == browser_->GetPopupDelegate()) {
} else if (this == browser_->UIT_GetPopupDelegate()) {
popup_bounds_ = rect; // The initial position of the popup.
}
}

View File

@@ -64,9 +64,9 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy) {
}
void BrowserWebViewDelegate::closeWidgetSoon() {
if (this == browser_->GetWebViewDelegate()) {
PostMessage(browser_->GetMainWndHandle(), WM_CLOSE, 0, 0);
} else if (this == browser_->GetPopupDelegate()) {
if (this == browser_->UIT_GetWebViewDelegate()) {
PostMessage(browser_->UIT_GetMainWndHandle(), WM_CLOSE, 0, 0);
} else if (this == browser_->UIT_GetPopupDelegate()) {
browser_->UIT_ClosePopupWidget();
}
}
@@ -91,10 +91,10 @@ WebRect BrowserWebViewDelegate::windowRect() {
}
void BrowserWebViewDelegate::setWindowRect(const WebRect& rect) {
if (this == browser_->GetWebViewDelegate()) {
if (this == browser_->UIT_GetWebViewDelegate()) {
// ignored
} else if (this == browser_->GetPopupDelegate()) {
MoveWindow(browser_->GetPopupWndHandle(),
} else if (this == browser_->UIT_GetPopupDelegate()) {
MoveWindow(browser_->UIT_GetPopupWndHandle(),
rect.x, rect.y, rect.width, rect.height, FALSE);
}
}
@@ -129,7 +129,7 @@ void BrowserWebViewDelegate::runModal() {
i = list->begin();
for (; i != list->end(); ++i) {
if (i->get()->IsPopup())
EnableWindow(i->get()->GetMainWndHandle(), FALSE);
EnableWindow(i->get()->UIT_GetMainWndHandle(), FALSE);
}
_Context->Unlock();
@@ -140,7 +140,7 @@ void BrowserWebViewDelegate::runModal() {
list = _Context->GetBrowserList();
i = list->begin();
for (; i != list->end(); ++i)
EnableWindow(i->get()->GetMainWndHandle(), TRUE);
EnableWindow(i->get()->UIT_GetMainWndHandle(), TRUE);
_Context->Unlock();
}
@@ -150,12 +150,13 @@ webkit::npapi::WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
const FilePath& file_path,
const std::string& mime_type)
{
HWND hwnd = browser_->GetWebViewHost() ?
browser_->GetWebViewHost()->view_handle() : NULL;
HWND hwnd = browser_->UIT_GetWebViewHost() ?
browser_->UIT_GetWebViewHost()->view_handle() : NULL;
if (!hwnd)
return NULL;
return webkit::npapi::WebPluginDelegateImpl::Create(file_path, mime_type, hwnd);
return webkit::npapi::WebPluginDelegateImpl::Create(file_path, mime_type,
hwnd);
}
void BrowserWebViewDelegate::CreatedPluginWindow(
@@ -242,7 +243,7 @@ void BrowserWebViewDelegate::showContextMenu(
WebFrame* frame, const WebContextMenuData& data)
{
POINT screen_pt = { data.mousePosition.x, data.mousePosition.y };
MapWindowPoints(browser_->GetMainWndHandle(), HWND_DESKTOP,
MapWindowPoints(browser_->UIT_GetMainWndHandle(), HWND_DESKTOP,
&screen_pt, 1);
HMENU menu = NULL;
@@ -356,7 +357,7 @@ void BrowserWebViewDelegate::showContextMenu(
// show the context menu
int selected_id = TrackPopupMenu(menu,
TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_RECURSE,
screen_pt.x, screen_pt.y, 0, browser_->GetMainWndHandle(), NULL);
screen_pt.x, screen_pt.y, 0, browser_->UIT_GetMainWndHandle(), NULL);
if(selected_id != 0) {
// An action was chosen
@@ -391,8 +392,8 @@ void BrowserWebViewDelegate::ShowJavaScriptAlert(WebFrame* webframe,
// TODO(cef): Think about what we should be showing as the prompt caption
std::wstring messageStr = message;
std::wstring titleStr = browser_->UIT_GetTitle();
MessageBox(browser_->GetMainWndHandle(), messageStr.c_str(), titleStr.c_str(),
MB_OK | MB_ICONWARNING);
MessageBox(browser_->UIT_GetMainWndHandle(), messageStr.c_str(),
titleStr.c_str(), MB_OK | MB_ICONWARNING);
}
bool BrowserWebViewDelegate::ShowJavaScriptConfirm(WebFrame* webframe,
@@ -401,7 +402,7 @@ bool BrowserWebViewDelegate::ShowJavaScriptConfirm(WebFrame* webframe,
// TODO(cef): Think about what we should be showing as the prompt caption
std::wstring messageStr = message;
std::wstring titleStr = browser_->UIT_GetTitle();
int rv = MessageBox(browser_->GetMainWndHandle(), messageStr.c_str(),
int rv = MessageBox(browser_->UIT_GetMainWndHandle(), messageStr.c_str(),
titleStr.c_str(), MB_YESNO | MB_ICONQUESTION);
return (rv == IDYES);
}
@@ -511,11 +512,12 @@ bool BrowserWebViewDelegate::ShowFileChooser(std::vector<FilePath>& file_names,
bool result = false;
if (multi_select) {
result = RunOpenMultiFileDialog(L"", browser_->GetMainWndHandle(),
result = RunOpenMultiFileDialog(L"", browser_->UIT_GetMainWndHandle(),
&file_names);
} else {
FilePath file_name;
result = RunOpenFileDialog(L"", browser_->GetMainWndHandle(), &file_name);
result = RunOpenFileDialog(L"", browser_->UIT_GetMainWndHandle(),
&file_name);
if (result)
file_names.push_back(file_name);
}

View File

@@ -52,90 +52,90 @@
CGContextSetRGBFillColor (context, 1, 0, 1, 1);
CGContextFillRect(context, NSRectToCGRect(rect));
if (browser_ && browser_->GetWebView()) {
if (browser_ && browser_->UIT_GetWebView()) {
gfx::Rect client_rect(NSRectToCGRect(rect));
// flip from cocoa coordinates
client_rect.set_y([self frame].size.height -
client_rect.height() - client_rect.y());
browser_->GetWebViewHost()->UpdatePaintRect(client_rect);
browser_->GetWebViewHost()->Paint();
browser_->UIT_GetWebViewHost()->UpdatePaintRect(client_rect);
browser_->UIT_GetWebViewHost()->Paint();
}
}
- (void)mouseDown:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)rightMouseDown:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)otherMouseDown:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)mouseUp:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)rightMouseUp:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)otherMouseUp:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)mouseMoved:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)mouseDragged:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)scrollWheel:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->WheelEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->WheelEvent(theEvent);
}
- (void)rightMouseDragged:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)otherMouseDragged:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)mouseEntered:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)mouseExited:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
}
- (void)keyDown:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->KeyEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->KeyEvent(theEvent);
}
- (void)keyUp:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->KeyEvent(theEvent);
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->KeyEvent(theEvent);
}
- (BOOL)isOpaque {
@@ -143,16 +143,16 @@
}
- (BOOL)canBecomeKeyView {
return browser_ && browser_->GetWebView();
return browser_ && browser_->UIT_GetWebView();
}
- (BOOL)acceptsFirstResponder {
return browser_ && browser_->GetWebView();
return browser_ && browser_->UIT_GetWebView();
}
- (BOOL)becomeFirstResponder {
if (browser_ && browser_->GetWebView()) {
browser_->GetWebViewHost()->SetFocus(YES);
if (browser_ && browser_->UIT_GetWebView()) {
browser_->UIT_GetWebViewHost()->SetFocus(YES);
return YES;
}
@@ -160,8 +160,8 @@
}
- (BOOL)resignFirstResponder {
if (browser_ && browser_->GetWebView()) {
browser_->GetWebViewHost()->SetFocus(NO);
if (browser_ && browser_->UIT_GetWebView()) {
browser_->UIT_GetWebViewHost()->SetFocus(NO);
return YES;
}
@@ -170,8 +170,8 @@
- (void)setFrame:(NSRect)frameRect {
[super setFrame:frameRect];
if (browser_ && browser_->GetWebView())
browser_->GetWebViewHost()->Resize(gfx::Rect(NSRectToCGRect(frameRect)));
if (browser_ && browser_->UIT_GetWebView())
browser_->UIT_GetWebViewHost()->Resize(gfx::Rect(NSRectToCGRect(frameRect)));
[self setNeedsDisplay:YES];
}