libcef: Update due to underlying chromium changes.

- Add unique IDs for browser instances because ResourceLoaderBridge::Create() now receives a routing ID instead of a WebFrame pointer.  The unique ID is assigned to a browser in CefContext::AddBrowser() and attached to a request in  BrowserWebViewDelegate::WillSendRequest().
- Add upload progress notification support to resource loader bridge.
- WebFrame::ExecuteJavaScript() changed to WebFrame::ExecuteScript().
- More functions moved into webkit_glue::WebKitClientImpl.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@22 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2009-03-24 15:06:38 +00:00
parent d942863661
commit 3f5a01e969
10 changed files with 137 additions and 29 deletions

View File

@ -7,6 +7,12 @@ development team. The current CEF revision may be newer than the last CEF
revision listed in this document. In that case, it means that the current CEF
revision is compatible with the last listed Chromium revision.
To update Chromium to a specific revision run the following command, where ####
is the Chromium revision number that you wish to download.
gclient sync --revision src@#### --force
Date | CEF Revision | Chromium Revision
-------------------------------------------------------------------------------
@ -22,3 +28,4 @@ Date | CEF Revision | Chromium Revision
2009-02-12 | /trunk@15 | /trunk@9652
2009-03-05 | /trunk@17 | /trunk@10987
2009-03-09 | /trunk@21 | /trunk@11252
2009-03-24 | /trunk@22 | /trunk@11768

View File

@ -10,13 +10,15 @@
#include "base/string_util.h"
#include "webkit/glue/webframe.h"
#include "webkit/glue/webscriptsource.h"
CefBrowserImpl::CefBrowserImpl(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler,
const std::wstring& url)
: window_info_(windowInfo), is_popup_(popup), is_modal_(false),
handler_(handler), webviewhost_(NULL), popuphost_(NULL), url_(url)
handler_(handler), webviewhost_(NULL), popuphost_(NULL), url_(url),
unique_id_(0)
{
delegate_ = new BrowserWebViewDelegate(this);
nav_controller_.reset(new BrowserNavigationController(this));
@ -451,7 +453,9 @@ void CefBrowserImpl::UIT_ExecuteJavaScript(const std::wstring& js_code,
else
frame = UIT_GetWebView()->GetMainFrame();
frame->ExecuteJavaScript(WideToUTF8(js_code), GURL(script_url), start_line);
frame->ExecuteScript(
webkit_glue::WebScriptSource(WideToUTF8(js_code), GURL(script_url),
start_line));
}
void CefBrowserImpl::UIT_GoBackOrForward(int offset)

View File

@ -192,6 +192,9 @@ public:
int UIT_SwitchFrameToPrintMediaType(WebFrame* frame);
int UIT_GetPagesCount(WebFrame* frame);
void UIT_SetUniqueID(int id) { unique_id_ = id; }
int UIT_GetUniqueID() { return unique_id_; }
#if defined(OS_WIN)
void UIT_DisableWebView(bool val);
bool UIT_IsWebViewDisabled() { return (webview_bitmap_ != NULL); }
@ -228,6 +231,9 @@ protected:
typedef std::map<std::wstring, CefRefPtr<CefJSContainer> > JSContainerMap;
JSContainerMap jscontainers_;
// Unique browser ID assigned by the context.
int unique_id_;
#if defined(OS_WIN)
HBITMAP webview_bitmap_;
SIZE webview_bitmap_size_;

View File

@ -40,10 +40,12 @@
#include "base/message_loop.h"
#include "base/ref_counted.h"
#include "base/string_util.h"
#include "base/time.h"
#include "base/thread.h"
#include "base/waitable_event.h"
#include "net/base/cookie_monster.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/base/net_util.h"
#include "net/base/upload_data.h"
#include "net/http/http_response_headers.h"
@ -107,6 +109,9 @@ struct RequestParams {
scoped_refptr<net::UploadData> upload;
};
// The interval for calls to RequestProxy::MaybeUpdateUploadProgress
static const int kUpdateUploadProgressIntervalMsec = 100;
// The RequestProxy does most of its work on the IO thread. The Start and
// Cancel methods are proxied over to the IO thread, where an URLRequest object
// is instantiated.
@ -115,7 +120,9 @@ class RequestProxy : public URLRequest::Delegate,
public:
// Takes ownership of the params.
RequestProxy(CefRefPtr<CefBrowser> browser)
: browser_(browser), buf_(new net::IOBuffer(kDataSize))
: browser_(browser),
buf_(new net::IOBuffer(kDataSize)),
last_upload_position_(0)
{
}
@ -150,6 +157,11 @@ class RequestProxy : public URLRequest::Delegate,
// various URLRequest callbacks. The event hooks, defined below, trigger
// these methods asynchronously.
void NotifyUploadProgress(uint64 position, uint64 size) {
if (peer_)
peer_->OnUploadProgress(position, size);
}
void NotifyReceivedRedirect(const GURL& new_url) {
if (peer_)
peer_->OnReceivedRedirect(new_url);
@ -197,7 +209,7 @@ class RequestProxy : public URLRequest::Delegate,
void AsyncStart(RequestParams* params) {
bool handled = false;
if (browser_) {
if (browser_.get()) {
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get())
{
@ -259,18 +271,25 @@ class RequestProxy : public URLRequest::Delegate,
AsyncReadData();
}
}
}
if(!handled)
{
request_.reset(new URLRequest(params->url, this));
request_->set_method(params->method);
request_->set_policy_url(params->policy_url);
request_->set_referrer(params->referrer.spec());
request_->SetExtraRequestHeaders(params->headers);
request_->set_load_flags(params->load_flags);
request_->set_upload(params->upload.get());
request_->set_context(request_context);
request_->Start();
if(!handled)
{
request_.reset(new URLRequest(params->url, this));
request_->set_method(params->method);
request_->set_policy_url(params->policy_url);
request_->set_referrer(params->referrer.spec());
request_->SetExtraRequestHeaders(params->headers);
request_->set_load_flags(params->load_flags);
request_->set_upload(params->upload.get());
request_->set_context(request_context);
request_->Start();
if (request_->has_upload() &&
params->load_flags & net::LOAD_ENABLE_UPLOAD_PROGRESS) {
upload_progress_timer_.Start(
base::TimeDelta::FromMilliseconds(kUpdateUploadProgressIntervalMsec),
this, &RequestProxy::MaybeUpdateUploadProgress);
}
}
@ -384,12 +403,44 @@ class RequestProxy : public URLRequest::Delegate,
std::string());
resource_stream_ = NULL;
} else {
if (upload_progress_timer_.IsRunning()) {
MaybeUpdateUploadProgress();
upload_progress_timer_.Stop();
}
DCHECK(request_.get());
OnCompletedRequest(request_->status(), std::string());
request_.reset(); // destroy on the io thread
}
}
// Called on the IO thread.
void MaybeUpdateUploadProgress() {
uint64 size = request_->get_upload()->GetContentLength();
uint64 position = request_->GetUploadProgress();
if (position == last_upload_position_)
return; // no progress made since last time
const uint64 kHalfPercentIncrements = 200;
const base::TimeDelta kOneSecond = base::TimeDelta::FromMilliseconds(1000);
uint64 amt_since_last = position - last_upload_position_;
base::TimeDelta time_since_last = base::TimeTicks::Now() -
last_upload_ticks_;
bool is_finished = (size == position);
bool enough_new_progress = (amt_since_last > (size /
kHalfPercentIncrements));
bool too_much_time_passed = time_since_last > kOneSecond;
if (is_finished || enough_new_progress || too_much_time_passed) {
owner_loop_->PostTask(FROM_HERE, NewRunnableMethod(
this, &RequestProxy::NotifyUploadProgress, position, size));
last_upload_ticks_ = base::TimeTicks::Now();
last_upload_position_ = position;
}
}
scoped_ptr<URLRequest> request_;
CefRefPtr<CefStreamReader> resource_stream_;
@ -407,6 +458,13 @@ class RequestProxy : public URLRequest::Delegate,
// not manage its lifetime, and we may only access it from the owner's
// message loop (owner_loop_).
ResourceLoaderBridge::Peer* peer_;
// Timer used to pull upload progress info.
base::RepeatingTimer<RequestProxy> upload_progress_timer_;
// Info used to determine whether or not to send an upload progress update.
uint64 last_upload_position_;
base::TimeTicks last_upload_ticks_;
};
//-----------------------------------------------------------------------------
@ -590,21 +648,19 @@ namespace webkit_glue {
// factory function
ResourceLoaderBridge* ResourceLoaderBridge::Create(
WebFrame* webframe,
const std::string& method,
const GURL& url,
const GURL& policy_url,
const GURL& referrer,
const std::string& headers,
int load_flags,
int origin_pid,
int requestor_pid,
ResourceType::Type request_type,
bool mixed_contents) {
return new ResourceLoaderBridgeImpl(
(webframe->GetView()->GetDelegate() ?
static_cast<BrowserWebViewDelegate*>(
webframe->GetView()->GetDelegate())->GetBrowser() : NULL),
method, url, policy_url, referrer, headers, load_flags);
bool mixed_contents,
int routing_id) {
CefRefPtr<CefBrowser> browser = _Context->GetBrowserByID(routing_id);
return new ResourceLoaderBridgeImpl(browser, method, url, policy_url,
referrer, headers, load_flags);
}
// Issue the proxy resolve request on the io thread, and wait

View File

@ -7,6 +7,7 @@
#include "browser_webkit_glue.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "config.h"
#include "webkit_version.h"

View File

@ -22,10 +22,14 @@
class BrowserWebKitInit : public webkit_glue::WebKitClientImpl {
public:
BrowserWebKitInit() {
v8::V8::SetCounterFunction(StatsTable::FindLocation);
WebKit::initialize(this);
WebKit::setLayoutTestMode(false);
WebKit::registerURLSchemeAsLocal(
ASCIIToUTF16(webkit_glue::GetUIResourceProtocol()));
WebKit::registerURLSchemeAsNoAccess(
ASCIIToUTF16(webkit_glue::GetUIResourceProtocol()));
WebKit::registerExtension(extensions_v8::GearsExtension::Get());
WebKit::registerExtension(extensions_v8::IntervalExtension::Get());
}
@ -38,6 +42,10 @@ class BrowserWebKitInit : public webkit_glue::WebKitClientImpl {
return &mime_registry_;
}
virtual WebKit::WebSandboxSupport* sandboxSupport() {
return NULL;
}
virtual uint64_t visitedLinkHash(const char* canonicalURL, size_t length) {
return 0;
}
@ -84,11 +92,6 @@ class BrowserWebKitInit : public webkit_glue::WebKitClientImpl {
return ASCIIToUTF16("en-US");
}
virtual void decrementStatsCounter(const char* name) {}
virtual void incrementStatsCounter(const char* name) {}
virtual void traceEventBegin(const char* name, void* id, const char* extra) {}
virtual void traceEventEnd(const char* name, void* id, const char* extra) {}
private:
webkit_glue::SimpleWebMimeRegistryImpl mime_registry_;
};

View File

@ -166,6 +166,9 @@ void BrowserWebViewDelegate::AssignIdentifierToRequest(WebView* webview,
void BrowserWebViewDelegate::WillSendRequest(WebView* webview,
uint32 identifier,
WebRequest* request) {
// The requestor ID is used by the resource loader bridge to locate the
// browser that originated the request.
request->SetRequestorID(browser_->UIT_GetUniqueID());
}
void BrowserWebViewDelegate::DidFinishLoading(WebView* webview,

View File

@ -255,6 +255,7 @@ CefContext::CefContext()
in_transition_ = false;
webprefs_ = NULL;
hinstance_ = ::GetModuleHandle(NULL);
next_browser_id_ = 1;
}
CefContext::~CefContext()
@ -462,7 +463,10 @@ bool CefContext::AddBrowser(CefRefPtr<CefBrowserImpl> browser)
}
if(!found)
{
browser->UIT_SetUniqueID(next_browser_id_++);
browserlist_.push_back(browser);
}
Unlock();
return !found;
@ -483,11 +487,32 @@ bool CefContext::RemoveBrowser(CefRefPtr<CefBrowserImpl> browser)
}
}
if (browserlist_.empty())
next_browser_id_ = 1;
Unlock();
return deleted;
}
CefRefPtr<CefBrowserImpl> CefContext::GetBrowserByID(int id)
{
CefRefPtr<CefBrowserImpl> browser;
Lock();
BrowserList::const_iterator it = browserlist_.begin();
for(; it != browserlist_.end(); ++it) {
if(it->get()->UIT_GetUniqueID() == id) {
browser = it->get();
break;
}
}
Unlock();
return browser;
}
void CefContext::SetMessageLoopForUI(MessageLoopForUI* loop)
{
Lock();

View File

@ -40,6 +40,7 @@ public:
bool AddBrowser(CefRefPtr<CefBrowserImpl> browser);
bool RemoveBrowser(CefRefPtr<CefBrowserImpl> browser);
CefRefPtr<CefBrowserImpl> GetBrowserByID(int id);
BrowserList* GetBrowserList() { return &browserlist_; }
// Returns true if the calling thread is the same as the UI thread
@ -79,6 +80,9 @@ protected:
base::AtExitManager at_exit_manager_;
// Initialize WebKit for this scope.
BrowserWebKitInit webkit_init_;
// Used for assigning unique IDs to browser instances.
int next_browser_id_;
friend DWORD WINAPI ThreadHandlerUI(LPVOID lpParam);
};

View File

@ -8,7 +8,6 @@
#include "base/basictypes.h"
#include "base/gfx/native_widget_types.h"
#include "base/gfx/rect.h"
#include "base/scoped_ptr.h"
#include "webwidget_host.h"
struct WebPreferences;