Introduce blink::ServiceProvider

This CL is a warmup for making hyperlinks actually work. ServiceProvider lets
the embedder inject a bundle of services that are specific to the embedding
context (e.g., NavigatorHost). Services that are independent to the embedding
context can be injected via blink::Platform.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/696733003
This commit is contained in:
Adam Barth 2014-10-31 10:54:03 -07:00
parent c125156a8c
commit 97565a73db
12 changed files with 90 additions and 24 deletions

View File

@ -38,13 +38,14 @@
namespace blink {
PassOwnPtr<FrameHost> FrameHost::create(Page& page)
PassOwnPtr<FrameHost> FrameHost::create(Page& page, ServiceProvider* services)
{
return adoptPtr(new FrameHost(page));
return adoptPtr(new FrameHost(page, services));
}
FrameHost::FrameHost(Page& page)
FrameHost::FrameHost(Page& page, ServiceProvider* services)
: m_page(&page)
, m_services(services)
, m_eventHandlerRegistry(adoptPtr(new EventHandlerRegistry(*this)))
{
}

View File

@ -42,6 +42,7 @@ namespace blink {
class Chrome;
class EventHandlerRegistry;
class Page;
class ServiceProvider;
class Settings;
class UseCounter;
class Visitor;
@ -58,7 +59,7 @@ class Visitor;
class FrameHost final : public DummyBase<FrameHost> {
WTF_MAKE_NONCOPYABLE(FrameHost); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public:
static PassOwnPtr<FrameHost> create(Page&);
static PassOwnPtr<FrameHost> create(Page&, ServiceProvider*);
~FrameHost();
// Careful: This function will eventually be removed.
@ -67,6 +68,8 @@ public:
Chrome& chrome() const;
UseCounter& useCounter() const;
ServiceProvider* services() const { return m_services; }
// Corresponds to pixel density of the device where this Page is
// being displayed. In multi-monitor setups this can vary between pages.
// This value does not account for Page zoom, use LocalFrame::devicePixelRatio instead.
@ -77,9 +80,10 @@ public:
void trace(Visitor*);
private:
explicit FrameHost(Page&);
FrameHost(Page&, ServiceProvider*);
RawPtr<Page> m_page;
ServiceProvider* m_services;
const OwnPtr<EventHandlerRegistry> m_eventHandlerRegistry;
};

View File

@ -91,7 +91,7 @@ float deviceScaleFactor(LocalFrame* frame)
return page->deviceScaleFactor();
}
Page::Page(PageClients& pageClients)
Page::Page(PageClients& pageClients, ServiceProvider* services)
: SettingsDelegate(Settings::create())
, m_animator(this)
, m_autoscrollController(AutoscrollController::create(*this))
@ -110,7 +110,7 @@ Page::Page(PageClients& pageClients)
#if ENABLE(ASSERT)
, m_isPainting(false)
#endif
, m_frameHost(FrameHost::create(*this))
, m_frameHost(FrameHost::create(*this, services))
{
ASSERT(m_editorClient);

View File

@ -56,6 +56,7 @@ class RenderObject;
class VisibleSelection;
class ScrollableArea;
class ScrollingCoordinator;
class ServiceProvider;
class Settings;
class SpellCheckerClient;
class UndoStack;
@ -83,7 +84,7 @@ public:
SpellCheckerClient* spellCheckerClient;
};
explicit Page(PageClients&);
Page(PageClients&, ServiceProvider*);
virtual ~Page();
void makeOrdinary();

View File

@ -59,7 +59,7 @@ DummyPageHolder::DummyPageHolder(
m_pageClients.editorClient = pageClients->editorClient;
m_pageClients.spellCheckerClient = pageClients->spellCheckerClient;
}
m_page = adoptPtr(new Page(m_pageClients));
m_page = adoptPtr(new Page(m_pageClients, 0));
// FIXME(sky): Delete the tests that use DummyPageHolder since
// they no longer work and we're not running them.

View File

@ -186,6 +186,7 @@ component("platform") {
"clipboard/ClipboardUtilities.h",
"clipboard/ClipboardUtilitiesPosix.cpp",
"exported/Platform.cpp",
"exported/ServiceProvider.cpp",
"exported/WebActiveGestureAnimation.cpp",
"exported/WebActiveGestureAnimation.h",
"exported/WebArrayBuffer.cpp",

View File

@ -0,0 +1,13 @@
// Copyright 2014 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 "config.h"
#include "public/platform/ServiceProvider.h"
namespace blink {
ServiceProvider::~ServiceProvider() {
}
} // namespace blink

View File

@ -0,0 +1,24 @@
// Copyright 2014 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.
#ifndef SKY_ENGINE_PUBLIC_PLATOFORM_SERVICES_H_
#define SKY_ENGINE_PUBLIC_PLATOFORM_SERVICES_H_
namespace mojo {
class NavigatorHost;
}
namespace blink {
class ServiceProvider {
public:
virtual mojo::NavigatorHost* NavigatorHost() = 0;
protected:
virtual ~ServiceProvider();
};
} // namespace blink
#endif

View File

@ -44,6 +44,7 @@
namespace blink {
class ServiceProvider;
class WebCompositorOutputSurface;
class WebElement;
class WebGestureEvent;
@ -66,6 +67,8 @@ struct WebSize;
// easily reused as part of an implementation of WebViewClient.
class WebViewClient : virtual public WebWidgetClient {
public:
virtual ServiceProvider* services() = 0;
// Editing -------------------------------------------------------------
// This method is called in response to WebView's handleInputEvent()

View File

@ -194,7 +194,7 @@ WebViewImpl::WebViewImpl(WebViewClient* client)
pageClients.editorClient = &m_editorClientImpl;
pageClients.spellCheckerClient = &m_spellCheckerClientImpl;
m_page = adoptPtr(new Page(pageClients));
m_page = adoptPtr(new Page(pageClients, m_client->services()));
m_page->makeOrdinary();
setDeviceScaleFactor(m_client->screenInfo().deviceScaleFactor);

View File

@ -187,6 +187,14 @@ void DocumentView::didCreateScriptContext(blink::WebLocalFrame* frame,
gin::ConvertToV8(isolate, internals));
}
blink::ServiceProvider* DocumentView::services() {
return this;
}
mojo::NavigatorHost* DocumentView::NavigatorHost() {
return navigator_host_.get();
}
void DocumentView::OnViewBoundsChanged(mojo::View* view,
const mojo::Rect& old_bounds,
const mojo::Rect& new_bounds) {

View File

@ -17,6 +17,7 @@
#include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
#include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
#include "mojo/services/public/interfaces/network/url_loader.mojom.h"
#include "sky/engine/public/platform/ServiceProvider.h"
#include "sky/engine/public/web/WebFrameClient.h"
#include "sky/engine/public/web/WebViewClient.h"
#include "sky/viewer/services/inspector_impl.h"
@ -35,6 +36,7 @@ class ScriptRunner;
class WebLayerTreeViewImpl;
class DocumentView : public mojo::InterfaceImpl<mojo::Application>,
public blink::ServiceProvider,
public blink::WebViewClient,
public blink::WebFrameClient,
public mojo::ViewManagerDelegate,
@ -67,31 +69,40 @@ class DocumentView : public mojo::InterfaceImpl<mojo::Application>,
virtual blink::WebLayerTreeView* initializeLayerTreeView();
// WebFrameClient methods:
virtual void frameDetached(blink::WebFrame*);
virtual blink::WebNavigationPolicy decidePolicyForNavigation(
const blink::WebFrameClient::NavigationPolicyInfo& info);
virtual void didAddMessageToConsole(
void frameDetached(blink::WebFrame*) override;
blink::WebNavigationPolicy decidePolicyForNavigation(
const blink::WebFrameClient::NavigationPolicyInfo& info) override;
void didAddMessageToConsole(
const blink::WebConsoleMessage& message,
const blink::WebString& source_name,
unsigned source_line,
const blink::WebString& stack_trace);
virtual void didCreateScriptContext(
blink::WebLocalFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId);
const blink::WebString& stack_trace) override;
void didCreateScriptContext(
blink::WebLocalFrame*,
v8::Handle<v8::Context>,
int extensionGroup,
int worldId) override;
// WebViewClient methods:
blink::ServiceProvider* services() override;
// Services methods:
mojo::NavigatorHost* NavigatorHost() override;
// ViewManagerDelegate methods:
virtual void OnEmbed(
void OnEmbed(
mojo::ViewManager* view_manager,
mojo::View* root,
mojo::ServiceProviderImpl* exported_services,
scoped_ptr<mojo::ServiceProvider> imported_services) override;
virtual void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override;
void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override;
// ViewObserver methods:
virtual void OnViewBoundsChanged(mojo::View* view,
const mojo::Rect& old_bounds,
const mojo::Rect& new_bounds) override;
virtual void OnViewDestroyed(mojo::View* view) override;
virtual void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override;
void OnViewBoundsChanged(mojo::View* view,
const mojo::Rect& old_bounds,
const mojo::Rect& new_bounds) override;
void OnViewDestroyed(mojo::View* view) override;
void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override;
void Load(mojo::URLResponsePtr response);