Make it possible to load a WebFrame from a URL

Previously, the WebFrame need to be created with a data pipe consumer handle.
This CL makes it possible to create a WebFrame with a URL and have the engine
issue the network request.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/940703002
This commit is contained in:
Adam Barth 2015-02-18 12:57:51 -08:00
parent 65382428a8
commit 3d8ffb7f52
6 changed files with 37 additions and 11 deletions

View File

@ -17,15 +17,12 @@
namespace blink {
using namespace mojo;
MojoLoader::MojoLoader(LocalFrame& frame)
: m_frame(frame)
{
}
void MojoLoader::load(const KURL& url, ScopedDataPipeConsumerHandle responseStream)
{
void MojoLoader::init(const KURL& url) {
DocumentInit init(url, &m_frame);
// FIXME(sky): Poorly named method for creating the FrameView:
@ -40,8 +37,11 @@ void MojoLoader::load(const KURL& url, ScopedDataPipeConsumerHandle responseStre
document->setReadyState(Document::Loading);
// FIXME: This should read the Content-Language out of the
// response headers and set them on Document::contentLanguage.
}
document->startParsing()->parse(responseStream.Pass(), base::Bind(base::DoNothing));
void MojoLoader::parse(mojo::ScopedDataPipeConsumerHandle responseStream) {
m_frame.document()->startParsing()->parse(responseStream.Pass(),
base::Bind(base::DoNothing));
}
}

View File

@ -16,7 +16,8 @@ class MojoLoader {
public:
explicit MojoLoader(LocalFrame&);
void load(const KURL&, mojo::ScopedDataPipeConsumerHandle);
void init(const KURL&);
void parse(mojo::ScopedDataPipeConsumerHandle);
private:
LocalFrame& m_frame;

View File

@ -134,7 +134,9 @@ public:
// Navigation ----------------------------------------------------------
virtual void load(const WebURL&, mojo::ScopedDataPipeConsumerHandle) = 0;
virtual void load(const WebURL&) = 0;
virtual void loadFromDataPipeWithURL(mojo::ScopedDataPipeConsumerHandle, const WebURL&) = 0;
// Editing -------------------------------------------------------------

View File

@ -257,9 +257,24 @@ void WebLocalFrameImpl::collectGarbage()
// TODO(dart): Implement.
}
void WebLocalFrameImpl::load(const WebURL& url, mojo::ScopedDataPipeConsumerHandle responseStream)
void WebLocalFrameImpl::loadFromDataPipeWithURL(mojo::ScopedDataPipeConsumerHandle responseStream, const WebURL& url)
{
frame()->mojoLoader().load(url, responseStream.Pass());
frame()->mojoLoader().init(url);
frame()->mojoLoader().parse(responseStream.Pass());
}
void WebLocalFrameImpl::load(const WebURL& url)
{
frame()->mojoLoader().init(url);
m_fetcher = adoptPtr(new MojoFetcher(this, url));
}
void WebLocalFrameImpl::OnReceivedResponse(mojo::URLResponsePtr response)
{
m_fetcher.clear();
if (!response->body.is_valid())
LOG(FATAL) << "Response has no body.";
frame()->mojoLoader().parse(response->body.Pass());
}
void WebLocalFrameImpl::replaceSelection(const WebString& text)

View File

@ -32,6 +32,7 @@
#define SKY_ENGINE_WEB_WEBLOCALFRAMEIMPL_H_
#include "sky/engine/core/frame/LocalFrame.h"
#include "sky/engine/platform/fetcher/MojoFetcher.h"
#include "sky/engine/platform/geometry/FloatRect.h"
#include "sky/engine/public/web/WebLocalFrame.h"
#include "sky/engine/web/FrameLoaderClientImpl.h"
@ -56,6 +57,7 @@ template <typename T> class WebVector;
// Implementation of WebFrame, note that this is a reference counted object.
class WebLocalFrameImpl final
: public WebLocalFrame
, public MojoFetcher::Client
, public RefCounted<WebLocalFrameImpl> {
public:
// WebFrame methods:
@ -70,7 +72,8 @@ public:
virtual void executeScript(const WebScriptSource&) override;
virtual void addMessageToConsole(const WebConsoleMessage&) override;
virtual void collectGarbage() override;
virtual void load(const WebURL&, mojo::ScopedDataPipeConsumerHandle);
virtual void load(const WebURL&);
virtual void loadFromDataPipeWithURL(mojo::ScopedDataPipeConsumerHandle, const WebURL&);
virtual void replaceSelection(const WebString&) override;
virtual void insertText(const WebString&) override;
virtual void setMarkedText(const WebString&, unsigned location, unsigned length) override;
@ -137,6 +140,9 @@ private:
// Sets the local core frame and registers destruction observers.
void setCoreFrame(PassRefPtr<LocalFrame>);
// MojoFetcher::Client
void OnReceivedResponse(mojo::URLResponsePtr) override;
FrameLoaderClientImpl m_frameLoaderClientImpl;
// The embedder retains a reference to the WebCore LocalFrame while it is active in the DOM. This
@ -145,6 +151,7 @@ private:
RefPtr<LocalFrame> m_frame;
WebFrameClient* m_client;
OwnPtr<MojoFetcher> m_fetcher;
// Stores the additional input events offset and scale when device metrics emulation is enabled.
IntSize m_inputEventsOffsetForEmulation;

View File

@ -151,7 +151,8 @@ void DocumentView::Load(mojo::URLResponsePtr response) {
web_view_ = blink::WebView::create(this);
ConfigureSettings(web_view_->settings());
web_view_->setMainFrame(blink::WebLocalFrame::create(this));
web_view_->mainFrame()->load(GURL(response->url), response->body.Pass());
web_view_->mainFrame()->loadFromDataPipeWithURL(
response->body.Pass(), GURL(response->url));
}
void DocumentView::initializeLayerTreeView() {