Commit 3c16f0f0 authored by ben@chromium.org's avatar ben@chromium.org

Eliminate Launchable. Use Navigator instead.

Adds URLResponse & body stream fields to NavigationDetails struct.

** not tested as part of the main chrome integration test suite **

R=aa@chromium.org
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278243 0039d316-1c4b-4281-b951-d872f2087c98
parent d1e7cd94
......@@ -4,6 +4,7 @@
#include "base/basictypes.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/services/navigation/navigation.mojom.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
......@@ -142,15 +143,18 @@ class Browser : public Application,
// launcher::LauncherClient:
virtual void OnLaunch(
const String& handler_url,
URLResponsePtr response,
ScopedDataPipeConsumerHandle response_body_stream) OVERRIDE {
navigation::ResponseDetailsPtr response_details) OVERRIDE {
content_node_->Embed(handler_url);
launcher::LaunchablePtr launchable;
ConnectTo(handler_url, &launchable);
launchable->OnLaunch(response.Pass(),
response_body_stream.Pass(),
content_node_->id());
navigation::NavigationDetailsPtr navigation_details(
navigation::NavigationDetails::New());
navigation_details->url = response_details->response->url;
navigation::NavigatorPtr navigator;
ConnectTo(handler_url, &navigator);
navigator->Navigate(content_node_->id(),
navigation_details.Pass(),
response_details.Pass());
}
scoped_ptr<ViewsInit> views_init_;
......
......@@ -49,9 +49,11 @@ class EmbeddedApp : public Application,
public:
explicit Navigator(EmbeddedApp* app) : app_(app) {}
private:
virtual void Navigate(uint32 node_id,
navigation::NavigationDetailsPtr details) OVERRIDE {
GURL url(details->url.To<std::string>());
virtual void Navigate(
uint32 node_id,
navigation::NavigationDetailsPtr navigation_details,
navigation::ResponseDetailsPtr response_details) OVERRIDE {
GURL url(navigation_details->url.To<std::string>());
if (!url.is_valid()) {
LOG(ERROR) << "URL is invalid.";
return;
......
......@@ -3,41 +3,42 @@
// found in the LICENSE file.
#include "mojo/public/cpp/application/application.h"
#include "mojo/services/navigation/navigation.mojom.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/types.h"
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
#include "mojo/services/public/interfaces/launcher/launcher.mojom.h"
namespace mojo {
namespace examples {
class HTMLViewer;
class LaunchableConnection : public InterfaceImpl<launcher::Launchable> {
class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
public:
explicit LaunchableConnection(HTMLViewer* viewer) : viewer_(viewer) {}
virtual ~LaunchableConnection() {}
explicit NavigatorImpl(HTMLViewer* viewer) : viewer_(viewer) {}
virtual ~NavigatorImpl() {}
private:
// Overridden from launcher::Launchable:
virtual void OnLaunch(
URLResponsePtr response,
ScopedDataPipeConsumerHandle response_body_stream,
view_manager::Id node_id) MOJO_OVERRIDE {
printf("In HTMLViewer, rendering url: %s\n", response->url.data());
// Overridden from navigation::Navigator:
virtual void Navigate(
uint32_t node_id,
navigation::NavigationDetailsPtr navigation_details,
navigation::ResponseDetailsPtr response_details) OVERRIDE {
printf("In HTMLViewer, rendering url: %s\n",
response_details->response->url.data());
printf("HTML: \n");
for (;;) {
char buf[512];
uint32_t num_bytes = sizeof(buf);
MojoResult result = ReadDataRaw(
response_body_stream.get(),
response_details->response_body_stream.get(),
buf,
&num_bytes,
MOJO_READ_DATA_FLAG_NONE);
if (result == MOJO_RESULT_SHOULD_WAIT) {
Wait(response_body_stream.get(),
Wait(response_details->response_body_stream.get(),
MOJO_HANDLE_SIGNAL_READABLE,
MOJO_DEADLINE_INDEFINITE);
} else if (result == MOJO_RESULT_OK) {
......@@ -55,7 +56,7 @@ class LaunchableConnection : public InterfaceImpl<launcher::Launchable> {
HTMLViewer* viewer_;
DISALLOW_COPY_AND_ASSIGN(LaunchableConnection);
DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
};
class HTMLViewer : public Application,
......@@ -65,11 +66,11 @@ class HTMLViewer : public Application,
virtual ~HTMLViewer() {}
private:
friend class LaunchableConnection;
friend class NavigatorImpl;
// Overridden from Application:
virtual void Initialize() OVERRIDE {
AddService<LaunchableConnection>(this);
AddService<NavigatorImpl>(this);
view_manager::ViewManager::Create(this, this);
}
......@@ -86,7 +87,7 @@ class HTMLViewer : public Application,
DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
};
void LaunchableConnection::UpdateView() {
void NavigatorImpl::UpdateView() {
viewer_->content_view_->SetColor(SK_ColorGREEN);
}
......
......@@ -6,12 +6,12 @@
#include "base/strings/string_tokenizer.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/services/navigation/navigation.mojom.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/types.h"
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
#include "mojo/services/public/interfaces/launcher/launcher.mojom.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
......@@ -20,29 +20,30 @@ namespace examples {
class ImageViewer;
class LaunchableConnection : public InterfaceImpl<launcher::Launchable> {
class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
public:
explicit LaunchableConnection(ImageViewer* viewer) : viewer_(viewer) {}
virtual ~LaunchableConnection() {}
explicit NavigatorImpl(ImageViewer* viewer) : viewer_(viewer) {}
virtual ~NavigatorImpl() {}
private:
// Overridden from launcher::Launchable:
virtual void OnLaunch(URLResponsePtr response,
ScopedDataPipeConsumerHandle response_body_stream,
uint32_t node_id) OVERRIDE {
int content_length = GetContentLength(response->headers);
// Overridden from navigation::Navigate:
virtual void Navigate(
uint32_t node_id,
navigation::NavigationDetailsPtr navigation_details,
navigation::ResponseDetailsPtr response_details) OVERRIDE {
int content_length = GetContentLength(response_details->response->headers);
unsigned char* data = new unsigned char[content_length];
unsigned char* buf = data;
uint32_t bytes_remaining = content_length;
uint32_t num_bytes = bytes_remaining;
while (bytes_remaining > 0) {
MojoResult result = ReadDataRaw(
response_body_stream.get(),
response_details->response_body_stream.get(),
buf,
&num_bytes,
MOJO_READ_DATA_FLAG_NONE);
if (result == MOJO_RESULT_SHOULD_WAIT) {
Wait(response_body_stream.get(),
Wait(response_details->response_body_stream.get(),
MOJO_HANDLE_SIGNAL_READABLE,
MOJO_DEADLINE_INDEFINITE);
} else if (result == MOJO_RESULT_OK) {
......@@ -80,7 +81,7 @@ class LaunchableConnection : public InterfaceImpl<launcher::Launchable> {
ImageViewer* viewer_;
DISALLOW_COPY_AND_ASSIGN(LaunchableConnection);
DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
};
class ImageViewer : public Application,
......@@ -97,7 +98,7 @@ class ImageViewer : public Application,
private:
// Overridden from Application:
virtual void Initialize() OVERRIDE {
AddService<LaunchableConnection>(this);
AddService<NavigatorImpl>(this);
view_manager::ViewManager::Create(this, this);
}
......@@ -122,8 +123,8 @@ class ImageViewer : public Application,
DISALLOW_COPY_AND_ASSIGN(ImageViewer);
};
void LaunchableConnection::UpdateView(view_manager::Id node_id,
const SkBitmap& bitmap) {
void NavigatorImpl::UpdateView(view_manager::Id node_id,
const SkBitmap& bitmap) {
viewer_->UpdateView(node_id, bitmap);
}
......
......@@ -45,9 +45,11 @@ class NestingApp : public Application,
public:
explicit Navigator(NestingApp* app) : app_(app) {}
private:
virtual void Navigate(uint32 node_id,
navigation::NavigationDetailsPtr details) OVERRIDE {
GURL url(details->url.To<std::string>());
virtual void Navigate(
uint32 node_id,
navigation::NavigationDetailsPtr navigation_details,
navigation::ResponseDetailsPtr response_details) OVERRIDE {
GURL url(navigation_details->url.To<std::string>());
if (!url.is_valid()) {
LOG(ERROR) << "URL is invalid.";
return;
......@@ -108,7 +110,11 @@ class NestingApp : public Application,
navigation::NavigationDetails::New());
details->url =
base::StringPrintf("%s/%s", kEmbeddedAppURL, color_.c_str());
navigator_->Navigate(nested_->id(), details.Pass());
navigation::ResponseDetailsPtr response_details(
navigation::ResponseDetails::New());
navigator_->Navigate(nested_->id(),
details.Pass(),
response_details.Pass());
}
}
......
......@@ -137,7 +137,13 @@ class WindowManager : public Application,
size_t index = node->children().size() - 1;
details->url = base::StringPrintf(
"%s/%x", kEmbeddedAppURL, kColors[index % arraysize(kColors)]);
navigator->Navigate(embedded->id(), details.Pass());
// TODO(beng): remove once nullable parameters land.
navigation::ResponseDetailsPtr response_details(
navigation::ResponseDetails::New());
navigator->Navigate(embedded->id(),
details.Pass(),
response_details.Pass());
}
}
......
......@@ -99,6 +99,7 @@
'mojo_application',
'mojo_cpp_bindings',
'mojo_environment_chromium',
'mojo_navigation_bindings',
'mojo_network_bindings',
'mojo_launcher_bindings',
'mojo_system_impl',
......@@ -119,6 +120,7 @@
'mojo_application',
'mojo_cpp_bindings',
'mojo_environment_chromium',
'mojo_navigation_bindings',
'mojo_network_bindings',
'mojo_launcher_bindings',
'mojo_system_impl',
......@@ -295,6 +297,7 @@
'mojo_geometry_lib',
'mojo_input_events_lib',
'mojo_launcher_bindings',
'mojo_navigation_bindings',
'mojo_system_impl',
'mojo_views_support',
'mojo_view_manager_bindings',
......
......@@ -194,6 +194,7 @@
],
'dependencies': [
'mojo_cpp_bindings',
'mojo_network_bindings',
],
},
{
......@@ -258,6 +259,7 @@
'dependencies': [
'mojo_cpp_bindings',
'mojo_network_bindings',
'mojo_navigation_bindings',
],
},
{
......
......@@ -145,9 +145,12 @@ void LaunchInstance::OnReceivedResponse(URLResponsePtr response) {
std::string content_type = GetContentType(response->headers);
std::string handler_url = app_->GetHandlerForContentType(content_type);
if (!handler_url.empty()) {
client_->OnLaunch(handler_url,
response.Pass(),
response_body_stream_.Pass());
navigation::ResponseDetailsPtr response_details =
navigation::ResponseDetails::New();
response_details->response = response.Pass();
response_details->response_body_stream = response_body_stream_.Pass();
client_->OnLaunch(handler_url, response_details.Pass());
}
}
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import "../public/interfaces/network/url_loader.mojom"
module mojo.navigation {
struct NavigationDetails {
......@@ -9,10 +11,21 @@ struct NavigationDetails {
// TODO(aa): method, data, etc.
};
struct ResponseDetails {
// TODO(beng): consider providing access to URLRequest too. Currently it is
// not possible to obtain from the URLLoader.
mojo.URLResponse response;
handle<data_pipe_consumer> response_body_stream;
};
// Applications implement this interface to support navigation of their views
// by embedders.
// |response_details| can be NULL when a navigation was not the result of a
// network load.
interface Navigator {
Navigate(uint32 node_id, NavigationDetails details);
Navigate(uint32 node_id,
NavigationDetails navigation_details,
ResponseDetails response_details);
};
}
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
import "../network/url_loader.mojom"
import "../../../navigation/navigation.mojom"
module mojo.launcher {
......@@ -13,15 +14,7 @@ interface Launcher {
[Client=Launcher]
interface LauncherClient {
OnLaunch(string handler_url,
mojo.URLResponse response,
handle<data_pipe_consumer> response_body_stream);
};
interface Launchable {
OnLaunch(mojo.URLResponse response,
handle<data_pipe_consumer> response_body_stream,
uint32 node_id);
OnLaunch(string handler_url, mojo.navigation.ResponseDetails response_details);
};
}
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