From ff7e8379fbc54b57ff860e54b3613ec16d64037b Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 2 Jun 2009 23:27:47 +0000 Subject: [PATCH] libcef: Update due to underlying chromium changes. - Underlying chromium changes fix Issue #27. - Navigation-related changes to work with WebDataSource. - Cookie-related changes for ResourceLoaderBridge. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@28 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- CHROMIUM_BUILD_COMPATIBILITY.txt | 1 + libcef/browser_impl.cc | 93 ++++++++++++++---------- libcef/browser_navigation_controller.h | 8 +- libcef/browser_request_context.cc | 3 +- libcef/browser_resource_loader_bridge.cc | 21 +++--- libcef/browser_resource_loader_bridge.h | 9 ++- libcef/browser_webkit_init.h | 15 ++-- libcef/browser_webview_delegate.cc | 27 ++++--- libcef/browser_webview_delegate.h | 12 ++- libcef/simple_clipboard_impl.cc | 3 +- libcef/webwidget_host.cc | 1 - 11 files changed, 116 insertions(+), 77 deletions(-) diff --git a/CHROMIUM_BUILD_COMPATIBILITY.txt b/CHROMIUM_BUILD_COMPATIBILITY.txt index 36645868b..cae15eb70 100644 --- a/CHROMIUM_BUILD_COMPATIBILITY.txt +++ b/CHROMIUM_BUILD_COMPATIBILITY.txt @@ -31,3 +31,4 @@ Date | CEF Revision | Chromium Revision 2009-03-24 | /trunk@22 | /trunk@11768 2009-04-27 | /trunk@23 | /trunk@14651 2009-05-15 | /trunk@24 | /trunk@16080 +2009-06-02 | /trunk@28 | /trunk@17397 diff --git a/libcef/browser_impl.cc b/libcef/browser_impl.cc index 0277af4f5..b31bab9a7 100644 --- a/libcef/browser_impl.cc +++ b/libcef/browser_impl.cc @@ -488,51 +488,66 @@ 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 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. - WebFrame* frame = GetWebView()->GetMainFrame(); + WebFrame* frame; if (!entry.GetTargetFrame().empty()) frame = GetWebView()->GetFrameWithName(entry.GetTargetFrame()); + else + frame = GetWebView()->GetMainFrame(); // TODO(mpcomplete): should we clear the target frame, or should // back/forward navigations maintain the target frame? - frame->LoadRequest(request.get()); + // A navigation resulting from loading a javascript URL should not be + // treated as a browser initiated event. Instead, we want it to look as if + // the page initiated any load resulting from JS execution. + if (!entry.GetURL().SchemeIs("javascript")) { + delegate_->set_pending_extra_data( + new BrowserExtraData(entry.GetPageID())); + } + + // 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 && !entry.GetContentState().empty()) { + DCHECK(entry.GetPageID() != -1); + frame->LoadHistoryState(entry.GetContentState()); + } else { + WebRequestCachePolicy cache_policy; + if (reload) { + cache_policy = WebRequestReloadIgnoringCacheData; + } else { + DCHECK(entry.GetPageID() == -1); + cache_policy = WebRequestUseProtocolCachePolicy; + } + + scoped_ptr request(WebRequest::Create(entry.GetURL())); + request->SetCachePolicy(cache_policy); + + 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()); + } + + frame->LoadRequest(request.get()); + } + + // In case LoadRequest failed before DidCreateDataSource was called. + delegate_->set_pending_extra_data(NULL); + // 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 diff --git a/libcef/browser_navigation_controller.h b/libcef/browser_navigation_controller.h index 6c81940d9..34d313bdc 100644 --- a/libcef/browser_navigation_controller.h +++ b/libcef/browser_navigation_controller.h @@ -13,6 +13,7 @@ #include "base/linked_ptr.h" #include "base/ref_counted.h" #include "googleurl/src/gurl.h" +#include "webkit/glue/webdatasource.h" #include "webkit/glue/weburlrequest.h" namespace net { @@ -23,11 +24,10 @@ class GURL; class CefBrowserImpl; // Associated with browser-initated navigations to hold tracking data. -class BrowserExtraRequestData : public WebRequest::ExtraData { +class BrowserExtraData : public WebDataSource::ExtraData { public: - BrowserExtraRequestData(int32 pending_page_id) - : WebRequest::ExtraData(), - pending_page_id(pending_page_id), + BrowserExtraData(int32 pending_page_id) + : pending_page_id(pending_page_id), request_committed(false) { } diff --git a/libcef/browser_request_context.cc b/libcef/browser_request_context.cc index f81a5fc48..512b059c7 100644 --- a/libcef/browser_request_context.cc +++ b/libcef/browser_request_context.cc @@ -32,7 +32,8 @@ void BrowserRequestContext::Init( accept_charset_ = "iso-8859-1,*,utf-8"; net::ProxyConfig proxy_config; - proxy_service_ = net::ProxyService::Create(no_proxy ? &proxy_config : NULL); + proxy_service_ = net::ProxyService::Create(no_proxy ? &proxy_config : NULL, + false, NULL, NULL); net::HttpCache *cache; if (cache_path.empty()) { diff --git a/libcef/browser_resource_loader_bridge.cc b/libcef/browser_resource_loader_bridge.cc index dbb2a06b5..b4107321d 100644 --- a/libcef/browser_resource_loader_bridge.cc +++ b/libcef/browser_resource_loader_bridge.cc @@ -46,6 +46,7 @@ #include "net/base/cookie_monster.h" #include "net/base/io_buffer.h" #include "net/base/load_flags.h" +#include "net/base/net_errors.h" #include "net/base/net_util.h" #include "net/base/upload_data.h" #include "net/http/http_response_headers.h" @@ -103,7 +104,7 @@ bool EnsureIOThread() { struct RequestParams { std::string method; GURL url; - GURL policy_url; + GURL first_party_for_cookies; GURL referrer; std::string headers; int load_flags; @@ -279,7 +280,7 @@ class RequestProxy : public URLRequest::Delegate, { request_.reset(new URLRequest(params->url, this)); request_->set_method(params->method); - request_->set_policy_url(params->policy_url); + request_->set_first_party_for_cookies(params->first_party_for_cookies); request_->set_referrer(params->referrer.spec()); request_->SetExtraRequestHeaders(params->headers); request_->set_load_flags(params->load_flags); @@ -528,7 +529,7 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge { ResourceLoaderBridgeImpl(CefRefPtr browser, const std::string& method, const GURL& url, - const GURL& policy_url, + const GURL& first_party_for_cookies, const GURL& referrer, const std::string& headers, int load_flags, @@ -538,7 +539,7 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge { proxy_(NULL) { params_->method = method; params_->url = url; - params_->policy_url = policy_url; + params_->first_party_for_cookies = first_party_for_cookies; params_->referrer = referrer; params_->headers = headers; params_->load_flags = load_flags; @@ -670,7 +671,7 @@ namespace webkit_glue { ResourceLoaderBridge* ResourceLoaderBridge::Create( const std::string& method, const GURL& url, - const GURL& policy_url, + const GURL& first_party_for_cookies, const GURL& referrer, const std::string& frame_origin, const std::string& main_frame_origin, @@ -681,7 +682,8 @@ ResourceLoaderBridge* ResourceLoaderBridge::Create( int app_cache_context_id, int routing_id) { CefRefPtr browser = _Context->GetBrowserByID(routing_id); - return new ResourceLoaderBridgeImpl(browser, method, url, policy_url, + return new ResourceLoaderBridgeImpl(browser, method, url, + first_party_for_cookies, referrer, headers, load_flags, app_cache_context_id); } @@ -732,8 +734,9 @@ void BrowserResourceLoaderBridge::Shutdown() { } } -void BrowserResourceLoaderBridge::SetCookie( - const GURL& url, const GURL& policy_url, const std::string& cookie) { +void BrowserResourceLoaderBridge::SetCookie(const GURL& url, + const GURL& first_party_for_cookies, + const std::string& cookie) { // Proxy to IO thread to synchronize w/ network loading. if (!EnsureIOThread()) { @@ -747,7 +750,7 @@ void BrowserResourceLoaderBridge::SetCookie( } std::string BrowserResourceLoaderBridge::GetCookies( - const GURL& url, const GURL& policy_url) { + const GURL& url, const GURL& first_party_for_cookies) { // Proxy to IO thread to synchronize w/ network loading if (!EnsureIOThread()) { diff --git a/libcef/browser_resource_loader_bridge.h b/libcef/browser_resource_loader_bridge.h index 8665db3b3..7231010d3 100644 --- a/libcef/browser_resource_loader_bridge.h +++ b/libcef/browser_resource_loader_bridge.h @@ -29,10 +29,11 @@ class BrowserResourceLoaderBridge { static void Shutdown(); // May only be called after Init. - static void SetCookie( - const GURL& url, const GURL& policy_url, const std::string& cookie); - static std::string GetCookies( - const GURL& url, const GURL& policy_url); + static void SetCookie(const GURL& url, + const GURL& first_party_for_cookies, + const std::string& cookie); + static std::string GetCookies(const GURL& url, + const GURL& first_party_for_cookies); }; #endif // _BROWSER_RESOURCE_LOADER_BRIDGE_H diff --git a/libcef/browser_webkit_init.h b/libcef/browser_webkit_init.h index 2d7ea783f..11cd9da34 100644 --- a/libcef/browser_webkit_init.h +++ b/libcef/browser_webkit_init.h @@ -64,15 +64,18 @@ class BrowserWebKitInit : public webkit_glue::WebKitClientImpl { return false; } - virtual void setCookies( - const WebKit::WebURL& url, const WebKit::WebURL& policy_url, - const WebKit::WebString& value) { - BrowserResourceLoaderBridge::SetCookie(url, policy_url, UTF16ToUTF8(value)); + virtual void setCookies(const WebKit::WebURL& url, + const WebKit::WebURL& first_party_for_cookies, + const WebKit::WebString& value) { + BrowserResourceLoaderBridge::SetCookie( + url, first_party_for_cookies, UTF16ToUTF8(value)); } virtual WebKit::WebString cookies( - const WebKit::WebURL& url, const WebKit::WebURL& policy_url) { - return UTF8ToUTF16(BrowserResourceLoaderBridge::GetCookies(url, policy_url)); + const WebKit::WebURL& url, + const WebKit::WebURL& first_party_for_cookies) { + return UTF8ToUTF16(BrowserResourceLoaderBridge::GetCookies( + url, first_party_for_cookies)); } virtual void prefetchHostName(const WebKit::WebString&) { diff --git a/libcef/browser_webview_delegate.cc b/libcef/browser_webview_delegate.cc index 2e508bf8e..892892a8b 100644 --- a/libcef/browser_webview_delegate.cc +++ b/libcef/browser_webview_delegate.cc @@ -217,6 +217,11 @@ void BrowserWebViewDelegate::DidFailLoadingWithError(WebView* webview, } +void BrowserWebViewDelegate::DidCreateDataSource(WebFrame* frame, + WebDataSource* ds) { + ds->SetExtraData(pending_extra_data_.release()); +} + void BrowserWebViewDelegate::DidStartProvisionalLoadForFrame( WebView* webview, WebFrame* frame, @@ -246,13 +251,12 @@ void BrowserWebViewDelegate::DidFailProvisionalLoadWithError( if (error.GetErrorCode() == net::ERR_ABORTED) return; - const WebRequest& failed_request = - frame->GetProvisionalDataSource()->GetRequest(); - BrowserExtraRequestData* extra_data = - static_cast(failed_request.GetExtraData()); + const WebDataSource* failed_ds = frame->GetProvisionalDataSource(); + BrowserExtraData* extra_data = + static_cast(failed_ds->GetExtraData()); bool replace = extra_data && extra_data->pending_page_id != -1; - scoped_ptr request(failed_request.Clone()); + scoped_ptr request(failed_ds->GetRequest().Clone()); request->SetURL(GURL("cef-error:")); std::string error_text; @@ -326,6 +330,7 @@ void BrowserWebViewDelegate::DidHandleOnloadEventsForFrame(WebView* webview, void BrowserWebViewDelegate::DidChangeLocationWithinPageForFrame( WebView* webview, WebFrame* frame, bool is_new_navigation) { + frame->GetDataSource()->SetExtraData(pending_extra_data_.release()); UpdateForCommittedLoad(frame, is_new_navigation); } @@ -607,7 +612,7 @@ void BrowserWebViewDelegate::UpdateAddressBar(WebView* webView) { if (!dataSource) return; - GURL gUrl = dataSource->GetRequest().GetMainDocumentURL(); + GURL gUrl = dataSource->GetRequest().GetFirstPartyForCookies(); */ } @@ -629,10 +634,8 @@ void BrowserWebViewDelegate::UpdateForCommittedLoad(WebFrame* frame, WebView* webview = browser_->GetWebView(); // Code duplicated from RenderView::DidCommitLoadForFrame. - const WebRequest& request = - webview->GetMainFrame()->GetDataSource()->GetRequest(); - BrowserExtraRequestData* extra_data = - static_cast(request.GetExtraData()); + BrowserExtraData* extra_data = static_cast( + frame->GetDataSource()->GetExtraData()); if (is_new_navigation) { // New navigation. @@ -678,6 +681,10 @@ void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) { handler->HandleAddressChange(browser_, browser_->GetCefFrame(frame), url); } + std::string state; + if (frame->GetCurrentHistoryState(&state)) + entry->SetContentState(state); + browser_->UIT_GetNavigationController()->DidNavigateToEntry(entry.release()); last_page_id_updated_ = std::max(last_page_id_updated_, page_id_); diff --git a/libcef/browser_webview_delegate.h b/libcef/browser_webview_delegate.h index 09897a43a..3e6659045 100644 --- a/libcef/browser_webview_delegate.h +++ b/libcef/browser_webview_delegate.h @@ -20,6 +20,7 @@ #include "base/basictypes.h" #include "base/ref_counted.h" +#include "base/scoped_ptr.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webview_delegate.h" #include "webkit/glue/webwidget_delegate.h" @@ -27,6 +28,7 @@ #include "browser_drag_delegate.h" #include "browser_drop_delegate.h" #endif +#include "browser_navigation_controller.h" class CefBrowserImpl; struct WebPreferences; @@ -102,6 +104,8 @@ class BrowserWebViewDelegate : public base::RefCounted, int edit_flags, const std::string& security_info, const std::string& frame_charset); + virtual void DidCreateDataSource(WebFrame* frame, + WebDataSource* ds); virtual void DidStartProvisionalLoadForFrame( WebView* webview, WebFrame* frame, @@ -232,7 +236,11 @@ class BrowserWebViewDelegate : public base::RefCounted, IDropTarget* drop_delegate() { return drop_delegate_.get(); } IDropSource* drag_delegate() { return drag_delegate_.get(); } #endif - + + void set_pending_extra_data(BrowserExtraData* extra_data) { + pending_extra_data_.reset(extra_data); + } + // Methods for modifying WebPreferences void SetUserStyleSheetEnabled(bool is_enabled); void SetUserStyleSheetLocation(const GURL& location); @@ -289,6 +297,8 @@ class BrowserWebViewDelegate : public base::RefCounted, int page_id_; int last_page_id_updated_; + scoped_ptr pending_extra_data_; + // true if we want to enable smart insert/delete. bool smart_insert_delete_enabled_; diff --git a/libcef/simple_clipboard_impl.cc b/libcef/simple_clipboard_impl.cc index 2f530d628..bc7ee6ef4 100644 --- a/libcef/simple_clipboard_impl.cc +++ b/libcef/simple_clipboard_impl.cc @@ -11,10 +11,9 @@ #include "base/lazy_instance.h" #include "base/string16.h" #include "googleurl/src/gurl.h" +#include "third_party/skia/include/core/SkBitmap.h" #include "webkit/glue/scoped_clipboard_writer_glue.h" -#include "SkBitmap.h" - // Clipboard glue #if defined(OS_WIN) diff --git a/libcef/webwidget_host.cc b/libcef/webwidget_host.cc index 215a66416..8223d95ea 100644 --- a/libcef/webwidget_host.cc +++ b/libcef/webwidget_host.cc @@ -51,7 +51,6 @@ WebWidgetHost* WebWidgetHost::Create(HWND parent_view, 0, 0, 0, 0, parent_view, NULL, GetModuleHandle(NULL), NULL); - TRACK_HWND_CREATION(host->view_); win_util::SetWindowUserData(host->view_, host); host->webwidget_ = WebWidget::Create(delegate);