2009-05-28 02:31:21 +02:00
|
|
|
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
2008-12-02 16:48:14 +01:00
|
|
|
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "precompiled_libcef.h"
|
|
|
|
#include "context.h"
|
|
|
|
#include "browser_impl.h"
|
|
|
|
#include "request_impl.h"
|
|
|
|
|
|
|
|
#include "base/string_util.h"
|
2009-05-15 17:09:51 +02:00
|
|
|
#include "webkit/api/public/WebScriptSource.h"
|
|
|
|
#include "webkit/api/public/WebString.h"
|
|
|
|
#include "webkit/api/public/WebURL.h"
|
2008-12-02 16:48:14 +01:00
|
|
|
#include "webkit/glue/webframe.h"
|
2009-04-28 02:29:14 +02:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
|
2009-04-28 02:29:14 +02:00
|
|
|
using WebKit::WebScriptSource;
|
|
|
|
using WebKit::WebString;
|
|
|
|
using WebKit::WebURL;
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
CefBrowserImpl::CefBrowserImpl(CefWindowInfo& windowInfo, bool popup,
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefHandler> handler)
|
2008-12-02 16:48:14 +01:00
|
|
|
: window_info_(windowInfo), is_popup_(popup), is_modal_(false),
|
2009-05-28 02:31:21 +02:00
|
|
|
handler_(handler), webviewhost_(NULL), popuphost_(NULL), unique_id_(0),
|
|
|
|
frame_main_(NULL)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
|
|
|
delegate_ = new BrowserWebViewDelegate(this);
|
|
|
|
nav_controller_.reset(new BrowserNavigationController(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::GoBack()
|
|
|
|
{
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
2009-05-28 02:31:21 +02:00
|
|
|
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_BACK));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::GoForward()
|
|
|
|
{
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
2009-05-28 02:31:21 +02:00
|
|
|
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_FORWARD));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::Reload()
|
|
|
|
{
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
2009-05-28 02:31:21 +02:00
|
|
|
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_RELOAD));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::StopLoad()
|
|
|
|
{
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
2009-05-28 02:31:21 +02:00
|
|
|
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_STOP));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::SetFocus(bool enable)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
if (_Context->RunningOnUIThread())
|
|
|
|
{
|
|
|
|
UIT_SetFocus(GetWebViewHost(), enable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_SetFocus,
|
|
|
|
GetWebViewHost(), enable));
|
|
|
|
}
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
bool CefBrowserImpl::IsPopup()
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
Lock();
|
|
|
|
bool popup = is_popup_;
|
|
|
|
Unlock();
|
|
|
|
return popup;
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefHandler> CefBrowserImpl::GetHandler()
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
return handler_;
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetMainFrame()
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
return GetCefFrame(GetWebView()->GetMainFrame());
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetFocusedFrame()
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
return GetCefFrame(GetWebView()->GetFocusedFrame());
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(const std::wstring& name)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
WebFrame* frame = GetWebView()->GetFrameWithName(name);
|
|
|
|
if(frame)
|
|
|
|
return GetCefFrame(frame);
|
|
|
|
return NULL;
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::GetFrameNames(std::vector<std::wstring>& names)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
WebView* view = GetWebView();
|
|
|
|
WebFrame* main_frame = view->GetMainFrame();
|
|
|
|
WebFrame* it = main_frame;
|
|
|
|
do {
|
|
|
|
if(it != main_frame)
|
|
|
|
names.push_back(it->GetName());
|
|
|
|
it = view->GetNextFrameAfter(it, true);
|
|
|
|
} while (it != main_frame);
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetCefFrame(WebFrame* frame)
|
2009-03-08 03:26:16 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefFrame> cef_frame;
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
WebView *view = GetWebView();
|
|
|
|
if(view) {
|
|
|
|
if(frame == view->GetMainFrame()) {
|
|
|
|
// Use or create the single main frame reference.
|
|
|
|
if(frame_main_ == NULL)
|
|
|
|
frame_main_ = new CefFrameImpl(this, std::wstring());
|
|
|
|
cef_frame = frame_main_;
|
|
|
|
} else {
|
|
|
|
// Locate or create the appropriate named reference.
|
|
|
|
std::wstring name = frame->GetName();
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
}
|
2009-03-08 03:26:16 +01:00
|
|
|
}
|
2009-05-28 02:31:21 +02:00
|
|
|
|
|
|
|
Unlock();
|
|
|
|
return cef_frame;
|
2009-03-08 03:26:16 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::RemoveCefFrame(const std::wstring& name)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
Lock();
|
|
|
|
|
|
|
|
if(name.empty())
|
|
|
|
frame_main_ = NULL;
|
|
|
|
else {
|
|
|
|
FrameMap::iterator it = frames_.find(name);
|
|
|
|
if(it != frames_.end())
|
|
|
|
frames_.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
Unlock();
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
WebFrame* CefBrowserImpl::GetWebFrame(CefRefPtr<CefFrame> frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
std::wstring name = frame->GetName();
|
|
|
|
if(name.empty())
|
|
|
|
return GetWebView()->GetMainFrame();
|
|
|
|
return GetWebView()->GetFrameWithName(name);
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
2009-05-28 02:31:21 +02:00
|
|
|
|
|
|
|
void CefBrowserImpl::Undo(CefRefPtr<CefFrame> frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->AddRef();
|
2008-12-02 16:48:14 +01:00
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
2009-05-28 02:31:21 +02:00
|
|
|
&CefBrowserImpl::UIT_HandleAction, MENU_ID_UNDO, frame.get()));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::Redo(CefRefPtr<CefFrame> frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->AddRef();
|
2008-12-02 16:48:14 +01:00
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
2009-05-28 02:31:21 +02:00
|
|
|
&CefBrowserImpl::UIT_HandleAction, MENU_ID_REDO, frame.get()));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::Cut(CefRefPtr<CefFrame> frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->AddRef();
|
2008-12-02 16:48:14 +01:00
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
2009-05-28 02:31:21 +02:00
|
|
|
&CefBrowserImpl::UIT_HandleAction, MENU_ID_CUT, frame.get()));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::Copy(CefRefPtr<CefFrame> frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->AddRef();
|
2008-12-02 16:48:14 +01:00
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
2009-05-28 02:31:21 +02:00
|
|
|
&CefBrowserImpl::UIT_HandleAction, MENU_ID_COPY, frame.get()));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::Paste(CefRefPtr<CefFrame> frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->AddRef();
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_HandleAction, MENU_ID_PASTE, frame.get()));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::Delete(CefRefPtr<CefFrame> frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->AddRef();
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_HandleAction, MENU_ID_DELETE, frame.get()));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::SelectAll(CefRefPtr<CefFrame> frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->AddRef();
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_HandleAction, MENU_ID_SELECTALL, frame.get()));
|
|
|
|
}
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::Print(CefRefPtr<CefFrame> frame)
|
|
|
|
{
|
|
|
|
frame->AddRef();
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_HandleAction, MENU_ID_PRINT, frame.get()));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::ViewSource(CefRefPtr<CefFrame> frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->AddRef();
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_HandleAction, MENU_ID_VIEWSOURCE, frame.get()));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::LoadRequest(CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
DCHECK(request.get() != NULL);
|
|
|
|
frame->AddRef();
|
|
|
|
request->AddRef();
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_LoadURLForRequestRef, frame.get(), request.get()));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::LoadURL(CefRefPtr<CefFrame> frame,
|
|
|
|
const std::wstring& url)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->AddRef();
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_LoadURL, frame.get(), url));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::LoadString(CefRefPtr<CefFrame> frame,
|
|
|
|
const std::wstring& string,
|
|
|
|
const std::wstring& url)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->AddRef();
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_LoadHTML, frame.get(), string, url));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::LoadStream(CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefStreamReader> stream,
|
|
|
|
const std::wstring& url)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
DCHECK(stream.get() != NULL);
|
|
|
|
frame->AddRef();
|
|
|
|
stream->AddRef();
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_LoadHTMLForStreamRef, frame.get(), stream.get(),
|
|
|
|
url));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::ExecuteJavaScript(CefRefPtr<CefFrame> frame,
|
|
|
|
const std::wstring& jsCode,
|
|
|
|
const std::wstring& scriptUrl,
|
|
|
|
int startLine)
|
|
|
|
{
|
|
|
|
frame->AddRef();
|
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(this,
|
|
|
|
&CefBrowserImpl::UIT_ExecuteJavaScript, frame.get(), jsCode, scriptUrl,
|
|
|
|
startLine));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring CefBrowserImpl::GetURL(CefRefPtr<CefFrame> frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
WebFrame* web_frame = GetWebFrame(frame);
|
|
|
|
if(web_frame)
|
|
|
|
return UTF8ToWide(web_frame->GetURL().spec());
|
|
|
|
return std::wstring();
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
|
|
|
|
CefRefPtr<CefHandler> handler,
|
|
|
|
const std::wstring& url)
|
|
|
|
{
|
|
|
|
if(!_Context.get())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::wstring newUrl = url;
|
|
|
|
|
|
|
|
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, handler, newUrl);
|
2009-03-05 02:10:06 +01:00
|
|
|
if(rv == RV_HANDLED)
|
2008-12-02 16:48:14 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserImpl> browser(
|
2009-05-28 02:31:21 +02:00
|
|
|
new CefBrowserImpl(windowInfo, popup, handler));
|
2008-12-02 16:48:14 +01:00
|
|
|
PostTask(FROM_HERE, NewRunnableMethod(browser.get(),
|
2009-05-28 02:31:21 +02:00
|
|
|
&CefBrowserImpl::UIT_CreateBrowser, newUrl));
|
2008-12-02 16:48:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-08 03:26:16 +01:00
|
|
|
CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
|
|
|
|
bool popup,
|
|
|
|
CefRefPtr<CefHandler> handler,
|
|
|
|
const std::wstring& url)
|
|
|
|
{
|
|
|
|
if(!_Context.get() || !_Context->RunningOnUIThread())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
std::wstring newUrl = url;
|
|
|
|
CefRefPtr<CefBrowser> alternateBrowser;
|
|
|
|
|
|
|
|
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, handler, newUrl);
|
|
|
|
if(rv == RV_HANDLED)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browser(new CefBrowserImpl(windowInfo, popup, handler));
|
|
|
|
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser(newUrl);
|
2009-03-08 03:26:16 +01:00
|
|
|
|
|
|
|
return browser;
|
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::UIT_LoadURL(CefFrame* frame,
|
|
|
|
const std::wstring& url)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-05-28 02:31:21 +02:00
|
|
|
UIT_LoadURLForRequest(frame, url, std::wstring(), NULL,
|
2008-12-02 16:48:14 +01:00
|
|
|
WebRequest::HeaderMap());
|
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::UIT_LoadURLForRequestRef(CefFrame* frame,
|
|
|
|
CefRequest* request)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
|
|
|
std::wstring url = request->GetURL();
|
|
|
|
std::wstring method = request->GetMethod();
|
|
|
|
|
|
|
|
CefRequestImpl *impl = static_cast<CefRequestImpl*>(request);
|
|
|
|
|
|
|
|
scoped_refptr<net::UploadData> upload_data;
|
|
|
|
CefRefPtr<CefPostData> postdata = impl->GetPostData();
|
|
|
|
if(postdata.get())
|
|
|
|
{
|
|
|
|
upload_data = new net::UploadData();
|
|
|
|
static_cast<CefPostDataImpl*>(postdata.get())->Get(*upload_data.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
WebRequest::HeaderMap headers;
|
|
|
|
impl->GetHeaderMap(headers);
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
UIT_LoadURLForRequest(frame, url, method, upload_data.get(), headers);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
request->Release();
|
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::UIT_LoadURLForRequest(CefFrame* frame,
|
|
|
|
const std::wstring& url,
|
2009-03-08 03:26:16 +01:00
|
|
|
const std::wstring& method,
|
|
|
|
net::UploadData *upload_data,
|
|
|
|
const WebRequest::HeaderMap& headers)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
if (url.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
GURL gurl(url);
|
|
|
|
|
|
|
|
if (!gurl.is_valid() && !gurl.has_scheme()) {
|
|
|
|
// Try to add "http://" at the beginning
|
|
|
|
gurl = GURL(std::wstring(L"http://") + url);
|
|
|
|
if (!gurl.is_valid())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
nav_controller_->LoadEntry(
|
|
|
|
new BrowserNavigationEntry(-1, gurl, std::wstring(), frame->GetName(),
|
|
|
|
method, upload_data, headers));
|
|
|
|
|
|
|
|
frame->Release();
|
2009-03-08 03:26:16 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::UIT_LoadHTML(CefFrame* frame,
|
|
|
|
const std::wstring& html,
|
2009-03-08 03:26:16 +01:00
|
|
|
const std::wstring& url)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
GURL gurl(url);
|
|
|
|
|
|
|
|
if (!gurl.is_valid() && !gurl.has_scheme()) {
|
|
|
|
// Try to add "http://" at the beginning
|
|
|
|
gurl = GURL(std::wstring(L"http://") + url);
|
|
|
|
if (!gurl.is_valid())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
WebFrame* web_frame = GetWebFrame(frame);
|
|
|
|
if(web_frame)
|
|
|
|
web_frame->LoadHTMLString(WideToUTF8(html), gurl);
|
|
|
|
|
|
|
|
frame->Release();
|
2009-03-08 03:26:16 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefFrame* frame,
|
|
|
|
CefStreamReader* stream,
|
2009-03-08 03:26:16 +01:00
|
|
|
const std::wstring& url)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
GURL gurl(url);
|
|
|
|
|
|
|
|
if (!gurl.is_valid() && !gurl.has_scheme()) {
|
|
|
|
// Try to add "http://" at the beginning
|
|
|
|
gurl = GURL(std::wstring(L"http://") + url);
|
|
|
|
if (!gurl.is_valid())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read all of the stream data into a std::string.
|
|
|
|
std::stringstream ss;
|
|
|
|
char buff[BUFFER_SIZE];
|
|
|
|
size_t read;
|
|
|
|
do {
|
|
|
|
read = stream->Read(buff, sizeof(char), BUFFER_SIZE-1);
|
|
|
|
if(read > 0) {
|
|
|
|
buff[read] = 0;
|
|
|
|
ss << buff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(read > 0);
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
WebFrame* web_frame = GetWebFrame(frame);
|
|
|
|
if(web_frame)
|
|
|
|
web_frame->LoadHTMLString(ss.str(), gurl);
|
2009-03-08 03:26:16 +01:00
|
|
|
|
|
|
|
stream->Release();
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->Release();
|
2009-03-08 03:26:16 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::UIT_ExecuteJavaScript(CefFrame* frame,
|
|
|
|
const std::wstring& js_code,
|
2009-01-29 18:48:16 +01:00
|
|
|
const std::wstring& script_url,
|
2009-05-28 02:31:21 +02:00
|
|
|
int start_line)
|
2009-01-29 18:48:16 +01:00
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
WebFrame* web_frame = GetWebFrame(frame);
|
|
|
|
if(web_frame) {
|
|
|
|
web_frame->ExecuteScript(
|
|
|
|
WebScriptSource(WebString(js_code), WebURL(GURL(script_url)),
|
|
|
|
start_line));
|
|
|
|
}
|
2009-01-29 18:48:16 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
frame->Release();
|
2009-01-29 18:48:16 +01:00
|
|
|
}
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
void CefBrowserImpl::UIT_GoBackOrForward(int offset)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
nav_controller_->GoToOffset(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_Reload()
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
nav_controller_->Reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
|
|
|
|
bool reload)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
WebRequestCachePolicy cache_policy;
|
|
|
|
if (reload) {
|
|
|
|
cache_policy = WebRequestReloadIgnoringCacheData;
|
|
|
|
} else if (entry.GetPageID() != -1) {
|
|
|
|
cache_policy = WebRequestReturnCacheDataElseLoad;
|
|
|
|
} else {
|
|
|
|
cache_policy = WebRequestUseProtocolCachePolicy;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_ptr<WebRequest> request(WebRequest::Create(entry.GetURL()));
|
|
|
|
request->SetCachePolicy(cache_policy);
|
|
|
|
// If we are reloading, then WebKit will use the state of the current page.
|
|
|
|
// Otherwise, we give it the state to navigate to.
|
|
|
|
if (!reload)
|
|
|
|
request->SetHistoryState(entry.GetContentState());
|
|
|
|
|
|
|
|
request->SetExtraData(
|
|
|
|
new BrowserExtraRequestData(entry.GetPageID()));
|
|
|
|
|
|
|
|
if(entry.GetMethod().size() > 0)
|
|
|
|
request->SetHttpMethod(WideToUTF8(entry.GetMethod()));
|
|
|
|
|
|
|
|
if(entry.GetHeaders().size() > 0)
|
|
|
|
request->SetHttpHeaders(entry.GetHeaders());
|
|
|
|
|
|
|
|
if(entry.GetUploadData())
|
|
|
|
{
|
|
|
|
if(request->GetHttpMethod() == "GET" || request->GetHttpMethod() == "HEAD")
|
|
|
|
request->SetHttpMethod("POST");
|
|
|
|
if(request->GetHttpHeaderValue("Content-Type").size() == 0) {
|
|
|
|
request->SetHttpHeaderValue(
|
|
|
|
"Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
}
|
|
|
|
request->SetUploadData(*entry.GetUploadData());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the right target frame for the entry.
|
2009-05-28 02:31:21 +02:00
|
|
|
WebFrame* frame = GetWebView()->GetMainFrame();
|
2008-12-02 16:48:14 +01:00
|
|
|
if (!entry.GetTargetFrame().empty())
|
2009-05-28 02:31:21 +02:00
|
|
|
frame = GetWebView()->GetFrameWithName(entry.GetTargetFrame());
|
2008-12-02 16:48:14 +01:00
|
|
|
// TODO(mpcomplete): should we clear the target frame, or should
|
|
|
|
// back/forward navigations maintain the target frame?
|
|
|
|
|
|
|
|
frame->LoadRequest(request.get());
|
|
|
|
// Restore focus to the main frame prior to loading new request.
|
|
|
|
// This makes sure that we don't have a focused iframe. Otherwise, that
|
|
|
|
// iframe would keep focus when the SetFocus called immediately after
|
|
|
|
// LoadRequest, thus making some tests fail (see http://b/issue?id=845337
|
|
|
|
// for more details).
|
2009-05-28 02:31:21 +02:00
|
|
|
GetWebView()->SetFocusedFrame(frame);
|
|
|
|
UIT_SetFocus(GetWebViewHost(), true);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(const std::wstring& url)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
CefWindowInfo info;
|
2009-03-06 20:20:44 +01:00
|
|
|
info.SetAsPopup(NULL, url.c_str());
|
2008-12-02 16:48:14 +01:00
|
|
|
CefRefPtr<CefHandler> handler = handler_;
|
|
|
|
std::wstring newUrl = url;
|
|
|
|
|
|
|
|
if(handler_.get())
|
|
|
|
{
|
|
|
|
// 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);
|
2009-03-05 02:10:06 +01:00
|
|
|
if(rv == RV_HANDLED)
|
2008-12-02 16:48:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowserImpl> browser(new CefBrowserImpl(info, true, handler));
|
|
|
|
browser->UIT_CreateBrowser(newUrl);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
return browser;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_Show(WebView* webview,
|
|
|
|
WindowOpenDisposition disposition)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
delegate_->Show(webview, disposition);
|
|
|
|
}
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
void CefBrowserImpl::UIT_HandleActionView(CefHandler::MenuId menuId)
|
|
|
|
{
|
|
|
|
return UIT_HandleAction(menuId, NULL);
|
|
|
|
}
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
|
2009-05-28 02:31:21 +02:00
|
|
|
CefFrame* frame)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
2009-05-28 02:31:21 +02:00
|
|
|
|
|
|
|
WebFrame* web_frame = NULL;
|
|
|
|
if(frame)
|
|
|
|
web_frame = GetWebFrame(frame);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
switch(menuId)
|
|
|
|
{
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_NAV_BACK:
|
2008-12-02 16:48:14 +01:00
|
|
|
UIT_GoBackOrForward(-1);
|
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_NAV_FORWARD:
|
2008-12-02 16:48:14 +01:00
|
|
|
UIT_GoBackOrForward(1);
|
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_NAV_RELOAD:
|
2008-12-02 16:48:14 +01:00
|
|
|
UIT_Reload();
|
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_NAV_STOP:
|
2009-05-28 02:31:21 +02:00
|
|
|
GetWebView()->StopLoading();
|
2008-12-02 16:48:14 +01:00
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_UNDO:
|
2009-05-28 02:31:21 +02:00
|
|
|
if(web_frame)
|
|
|
|
web_frame->Undo();
|
2008-12-02 16:48:14 +01:00
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_REDO:
|
2009-05-28 02:31:21 +02:00
|
|
|
if(web_frame)
|
|
|
|
web_frame->Redo();
|
2008-12-02 16:48:14 +01:00
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_CUT:
|
2009-05-28 02:31:21 +02:00
|
|
|
if(web_frame)
|
|
|
|
web_frame->Cut();
|
2008-12-02 16:48:14 +01:00
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_COPY:
|
2009-05-28 02:31:21 +02:00
|
|
|
if(web_frame)
|
|
|
|
web_frame->Copy();
|
2008-12-02 16:48:14 +01:00
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_PASTE:
|
2009-05-28 02:31:21 +02:00
|
|
|
if(web_frame)
|
|
|
|
web_frame->Paste();
|
2008-12-02 16:48:14 +01:00
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_DELETE:
|
2009-05-28 02:31:21 +02:00
|
|
|
if(web_frame)
|
|
|
|
web_frame->Delete();
|
2008-12-02 16:48:14 +01:00
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_SELECTALL:
|
2009-05-28 02:31:21 +02:00
|
|
|
if(web_frame)
|
|
|
|
web_frame->SelectAll();
|
2008-12-02 16:48:14 +01:00
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_PRINT:
|
2009-05-28 02:31:21 +02:00
|
|
|
if(web_frame)
|
|
|
|
UIT_PrintPages(web_frame);
|
2008-12-02 16:48:14 +01:00
|
|
|
break;
|
2009-03-05 02:10:06 +01:00
|
|
|
case MENU_ID_VIEWSOURCE:
|
2009-05-28 02:31:21 +02:00
|
|
|
if(web_frame)
|
|
|
|
UIT_ViewDocumentString(web_frame);
|
2008-12-02 16:48:14 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-05-28 02:31:21 +02:00
|
|
|
|
|
|
|
if(frame)
|
|
|
|
frame->Release();
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|