Break dependency of native_viewport_service on mojo::shell::Context

BUG=

Review URL: https://codereview.chromium.org/404913002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284660 0039d316-1c4b-4281-b951-d872f2087c98
parent 1334c961
......@@ -19,10 +19,6 @@ class Event;
}
namespace mojo {
namespace shell {
class Context;
}
namespace services {
class NativeViewportDelegate {
......@@ -52,9 +48,7 @@ class NativeViewport {
virtual void SetCapture() = 0;
virtual void ReleaseCapture() = 0;
// |context| is NULL when loaded into separate process.
static scoped_ptr<NativeViewport> Create(shell::Context* context,
NativeViewportDelegate* delegate);
static scoped_ptr<NativeViewport> Create(NativeViewportDelegate* delegate);
};
} // namespace services
......
......@@ -9,7 +9,6 @@
#include "base/android/jni_android.h"
#include "jni/NativeViewportAndroid_jni.h"
#include "mojo/shell/context.h"
#include "ui/events/event.h"
#include "ui/gfx/point.h"
......@@ -38,10 +37,8 @@ bool NativeViewportAndroid::Register(JNIEnv* env) {
return RegisterNativesImpl(env);
}
NativeViewportAndroid::NativeViewportAndroid(shell::Context* context,
NativeViewportDelegate* delegate)
NativeViewportAndroid::NativeViewportAndroid(NativeViewportDelegate* delegate)
: delegate_(delegate),
context_(context),
window_(NULL),
id_generator_(0),
weak_factory_(this) {
......@@ -103,8 +100,10 @@ bool NativeViewportAndroid::TouchEvent(JNIEnv* env, jobject obj,
void NativeViewportAndroid::Init(const gfx::Rect& bounds) {
JNIEnv* env = base::android::AttachCurrentThread();
Java_NativeViewportAndroid_createForActivity(env, context_->activity(),
reinterpret_cast<jlong>(this));
Java_NativeViewportAndroid_createForActivity(
env,
base::android::GetApplicationContext(),
reinterpret_cast<jlong>(this));
}
void NativeViewportAndroid::Show() {
......@@ -151,10 +150,8 @@ void NativeViewportAndroid::ReleaseWindow() {
// static
scoped_ptr<NativeViewport> NativeViewport::Create(
shell::Context* context,
NativeViewportDelegate* delegate) {
return scoped_ptr<NativeViewport>(
new NativeViewportAndroid(context, delegate)).Pass();
return scoped_ptr<NativeViewport>(new NativeViewportAndroid(delegate)).Pass();
}
} // namespace services
......
......@@ -29,8 +29,7 @@ class MOJO_NATIVE_VIEWPORT_EXPORT NativeViewportAndroid
public:
static MOJO_NATIVE_VIEWPORT_EXPORT bool Register(JNIEnv* env);
explicit NativeViewportAndroid(shell::Context* context,
NativeViewportDelegate* delegate);
explicit NativeViewportAndroid(NativeViewportDelegate* delegate);
virtual ~NativeViewportAndroid();
void Destroy(JNIEnv* env, jobject obj);
......@@ -54,7 +53,6 @@ class MOJO_NATIVE_VIEWPORT_EXPORT NativeViewportAndroid
void ReleaseWindow();
NativeViewportDelegate* delegate_;
shell::Context* context_;
ANativeWindow* window_;
gfx::Rect bounds_;
ui::SequentialIDGenerator id_generator_;
......
......@@ -79,7 +79,6 @@ class NativeViewportMac : public NativeViewport {
// static
scoped_ptr<NativeViewport> NativeViewport::Create(
shell::Context* context,
NativeViewportDelegate* delegate) {
return scoped_ptr<NativeViewport>(new NativeViewportMac(delegate)).Pass();
}
......
......@@ -89,7 +89,6 @@ class NativeViewportOzone : public NativeViewport,
// static
scoped_ptr<NativeViewport> NativeViewport::Create(
shell::Context* context,
NativeViewportDelegate* delegate) {
return scoped_ptr<NativeViewport>(new NativeViewportOzone(delegate)).Pass();
}
......
......@@ -33,10 +33,8 @@ class NativeViewportImpl
: public InterfaceImpl<mojo::NativeViewport>,
public NativeViewportDelegate {
public:
NativeViewportImpl(ApplicationConnection* connection,
shell::Context* context)
: context_(context),
widget_(gfx::kNullAcceleratedWidget),
explicit NativeViewportImpl(ApplicationConnection* connection)
: widget_(gfx::kNullAcceleratedWidget),
waiting_for_event_ack_(false),
weak_factory_(this) {}
virtual ~NativeViewportImpl() {
......@@ -46,8 +44,7 @@ class NativeViewportImpl
}
virtual void Create(RectPtr bounds) OVERRIDE {
native_viewport_ =
services::NativeViewport::Create(context_, this);
native_viewport_ = services::NativeViewport::Create(this);
native_viewport_->Init(bounds.To<gfx::Rect>());
client()->OnCreated();
OnBoundsChanged(bounds.To<gfx::Rect>());
......@@ -146,7 +143,6 @@ class NativeViewportImpl
command_buffer_.reset();
}
shell::Context* context_;
gfx::AcceleratedWidget widget_;
scoped_ptr<services::NativeViewport> native_viewport_;
InterfaceRequest<CommandBuffer> command_buffer_request_;
......@@ -157,27 +153,24 @@ class NativeViewportImpl
class NVSDelegate : public ApplicationDelegate {
public:
NVSDelegate(shell::Context* context) : context_(context) {}
NVSDelegate() {}
virtual ~NVSDelegate() {}
virtual bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
connection->AddService<NativeViewportImpl>(context_);
connection->AddService<NativeViewportImpl>();
return true;
}
private:
mojo::shell::Context* context_;
};
} // namespace services
} // namespace mojo
MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl*
CreateNativeViewportService(
mojo::shell::Context* context,
mojo::ScopedMessagePipeHandle service_provider_handle) {
mojo::ApplicationImpl* app = new mojo::ApplicationImpl(
new mojo::services::NVSDelegate(context), service_provider_handle.Pass());
ScopedMessagePipeHandle service_provider_handle) {
ApplicationImpl* app = new ApplicationImpl(
new NVSDelegate(), service_provider_handle.Pass());
return app;
}
} // namespace services
} // namespace mojo
......@@ -10,9 +10,14 @@
#include "mojo/services/native_viewport/native_viewport_export.h"
#include "mojo/shell/context.h"
namespace mojo {
namespace services {
MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl*
CreateNativeViewportService(
mojo::shell::Context* context,
mojo::ScopedMessagePipeHandle service_provider_handle);
ScopedMessagePipeHandle service_provider_handle);
} // namespace services
} // namespace mojo
#endif // MOJO_SERVICES_NATIVE_VIEWPORT_SERVICE_H_
......@@ -41,7 +41,6 @@ class NativeViewportStub : public NativeViewport {
// static
scoped_ptr<NativeViewport> NativeViewport::Create(
shell::Context* context,
NativeViewportDelegate* delegate) {
return scoped_ptr<NativeViewport>(new NativeViewportStub(delegate)).Pass();
}
......
......@@ -161,7 +161,6 @@ class NativeViewportWin : public gfx::WindowImpl,
// static
scoped_ptr<NativeViewport> NativeViewport::Create(
shell::Context* context,
NativeViewportDelegate* delegate) {
return scoped_ptr<NativeViewport>(new NativeViewportWin(delegate)).Pass();
}
......
......@@ -112,7 +112,6 @@ class NativeViewportX11 : public NativeViewport,
// static
scoped_ptr<NativeViewport> NativeViewport::Create(
shell::Context* context,
NativeViewportDelegate* delegate) {
return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass();
}
......
......@@ -38,7 +38,6 @@ LazyInstance<scoped_ptr<base::android::JavaHandlerThread> > g_shell_thread =
void RunShell(std::vector<GURL> app_urls) {
shell::Context* shell_context = new shell::Context();
shell_context->set_activity(base::android::GetApplicationContext());
shell_context->set_ui_loop(g_java_message_loop.Get().get());
g_context.Get().reset(shell_context);
......
......@@ -65,21 +65,20 @@ static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER;
class Context::NativeViewportServiceLoader : public ServiceLoader {
public:
explicit NativeViewportServiceLoader(Context* context) : context_(context) {}
NativeViewportServiceLoader() {}
virtual ~NativeViewportServiceLoader() {}
private:
virtual void LoadService(ServiceManager* manager,
const GURL& url,
ScopedMessagePipeHandle shell_handle) OVERRIDE {
app_.reset(::CreateNativeViewportService(context_, shell_handle.Pass()));
app_.reset(services::CreateNativeViewportService(shell_handle.Pass()));
}
virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE {
}
Context* context_;
scoped_ptr<ApplicationImpl> app_;
DISALLOW_COPY_AND_ASSIGN(NativeViewportServiceLoader);
};
......@@ -108,14 +107,14 @@ Context::Context()
service_manager_.SetLoaderForURL(
scoped_ptr<ServiceLoader>(
new UIServiceLoader(
scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader(this)),
scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()),
this)),
GURL("mojo:mojo_native_viewport_service"));
#else
service_manager_.SetLoaderForURL(
scoped_ptr<ServiceLoader>(
new BackgroundServiceLoader(
scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader(this)),
scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()),
"native_viewport",
base::MessageLoop::TYPE_UI)),
GURL("mojo:mojo_native_viewport_service"));
......
......@@ -36,8 +36,6 @@ class Context {
MojoURLResolver* mojo_url_resolver() { return &mojo_url_resolver_; }
#if defined(OS_ANDROID)
jobject activity() const { return activity_.obj(); }
void set_activity(jobject activity) { activity_.Reset(NULL, activity); }
base::MessageLoop* ui_loop() const { return ui_loop_; }
void set_ui_loop(base::MessageLoop* ui_loop) { ui_loop_ = ui_loop; }
#endif // defined(OS_ANDROID)
......@@ -50,7 +48,6 @@ class Context {
MojoURLResolver mojo_url_resolver_;
scoped_ptr<Spy> spy_;
#if defined(OS_ANDROID)
base::android::ScopedJavaGlobalRef<jobject> activity_;
base::MessageLoop* ui_loop_;
#endif // defined(OS_ANDROID)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment