Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Rename xwalk::Runtime to xwalk::XWalkContent
Browse files Browse the repository at this point in the history
Rename xwalk::Runtime to xwalk::XWalkContent and stop
compiling it on Android.
  • Loading branch information
Mikhail Pozdnyakov committed Dec 3, 2014
1 parent 8689eaa commit 0ca4a32
Show file tree
Hide file tree
Showing 43 changed files with 360 additions and 337 deletions.
55 changes: 27 additions & 28 deletions application/browser/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "xwalk/application/common/application_manifest_constants.h"
#include "xwalk/application/common/constants.h"
#include "xwalk/application/common/manifest_handlers/warp_handler.h"
#include "xwalk/runtime/browser/runtime.h"
#include "xwalk/runtime/browser/xwalk_content.h"
#include "xwalk/runtime/browser/runtime_ui_delegate.h"
#include "xwalk/runtime/browser/xwalk_browser_context.h"
#include "xwalk/runtime/browser/xwalk_runner.h"
Expand Down Expand Up @@ -204,7 +204,7 @@ ui::WindowShowState Application::GetWindowShowState<Manifest::TYPE_MANIFEST>(
}

bool Application::Launch(const LaunchParams& launch_params) {
if (!runtimes_.empty()) {
if (!pages_.empty()) {
LOG(ERROR) << "Attempt to launch app with id " << id()
<< ", but it is already running.";
return false;
Expand All @@ -220,14 +220,14 @@ bool Application::Launch(const LaunchParams& launch_params) {

remote_debugging_enabled_ = launch_params.remote_debugging;
auto site = content::SiteInstance::CreateForURL(browser_context_, url);
Runtime* runtime = Runtime::Create(browser_context_, site);
runtime->set_observer(this);
runtimes_.push_back(runtime);
render_process_host_ = runtime->GetRenderProcessHost();
XWalkContent* page = XWalkContent::Create(browser_context_, site);
page->set_observer(this);
pages_.push_back(page);
render_process_host_ = page->GetRenderProcessHost();
render_process_host_->AddObserver(this);
web_contents_ = runtime->web_contents();
web_contents_ = page->web_contents();
InitSecurityPolicy();
runtime->LoadURL(url);
page->LoadURL(url);

NativeAppWindow::CreateParams params;
params.net_wm_pid = launch_params.launcher_pid;
Expand All @@ -236,9 +236,9 @@ bool Application::Launch(const LaunchParams& launch_params) {
GetWindowShowState<Manifest::TYPE_MANIFEST>(launch_params);

window_show_params_ = params;
// Only the first runtime can have a launch screen.
// Only the first page can have a launch screen.
params.splash_screen_path = GetSplashScreenPath();
runtime->set_ui_delegate(DefaultRuntimeUIDelegate::Create(runtime, params));
page->set_ui_delegate(DefaultRuntimeUIDelegate::Create(page, params));
// We call "Show" after RP is initialized to reduce
// the application start up time.

Expand All @@ -256,32 +256,31 @@ GURL Application::GetAbsoluteURLFromKey(const std::string& key) {
}

void Application::Terminate() {
std::vector<Runtime*> to_be_closed(runtimes_.get());
for (Runtime* runtime : to_be_closed)
runtime->Close();
std::vector<XWalkContent*> to_be_closed(pages_.get());
for (XWalkContent* content : to_be_closed)
content->Close();
}

int Application::GetRenderProcessHostID() const {
DCHECK(render_process_host_);
return render_process_host_->GetID();
}

void Application::OnNewRuntimeAdded(Runtime* runtime) {
runtime->set_remote_debugging_enabled(remote_debugging_enabled_);
runtime->set_observer(this);
runtime->set_ui_delegate(
DefaultRuntimeUIDelegate::Create(runtime, window_show_params_));
runtime->Show();
runtimes_.push_back(runtime);
void Application::OnContentCreated(XWalkContent* page) {
page->set_remote_debugging_enabled(remote_debugging_enabled_);
page->set_observer(this);
page->set_ui_delegate(
DefaultRuntimeUIDelegate::Create(page, window_show_params_));
page->Show();
pages_.push_back(page);
}

void Application::OnRuntimeClosed(Runtime* runtime) {
auto found = std::find(runtimes_.begin(), runtimes_.end(), runtime);
CHECK(found != runtimes_.end());
LOG(INFO) << "Application::OnRuntimeClosed " << runtime;
runtimes_.erase(found);
void Application::OnContentClosed(XWalkContent* page) {
auto found = std::find(pages_.begin(), pages_.end(), page);
CHECK(found != pages_.end());
pages_.erase(found);

if (runtimes_.empty())
if (pages_.empty())
base::MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&Application::NotifyTermination,
weak_factory_.GetWeakPtr()));
Expand Down Expand Up @@ -309,8 +308,8 @@ void Application::NotifyTermination() {
}

void Application::RenderChannelCreated() {
CHECK(!runtimes_.empty());
runtimes_.front()->Show();
CHECK(!pages_.empty());
pages_.front()->Show();
}

bool Application::UseExtension(const std::string& extension_name) const {
Expand Down
23 changes: 12 additions & 11 deletions application/browser/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#include "ui/base/ui_base_types.h"
#include "xwalk/application/browser/application_security_policy.h"
#include "xwalk/application/common/application_data.h"
#include "xwalk/runtime/browser/runtime.h"
#include "xwalk/runtime/browser/ui/native_app_window.h"
#include "xwalk/runtime/browser/xwalk_content.h"

namespace content {
class RenderProcessHost;
Expand All @@ -43,15 +44,15 @@ class ApplicationSecurityPolicy;
// ApplicationService will delete an Application instance when it is
// terminated.
// There's one-to-one correspondence between Application and Render Process
// Host, obtained from its "runtimes" (pages).
class Application : public Runtime::Observer,
// Host, obtained from its "contents" (pages).
class Application : public XWalkContent::Observer,
public content::RenderProcessHostObserver {
public:
virtual ~Application();

class Observer {
public:
// Invoked when application is terminated - all its pages (runtimes)
// Invoked when application is terminated - all its pages (contents)
// are closed.
virtual void OnApplicationTerminated(Application* app) {}

Expand All @@ -68,7 +69,7 @@ class Application : public Runtime::Observer,
bool remote_debugging;
};

// Closes all the application's runtimes (application pages).
// Closes all the application's pages (application pages).
// NOTE: Application is terminated asynchronously.
// Please use ApplicationService::Observer::WillDestroyApplication()
// interface to be notified about actual app termination.
Expand All @@ -77,7 +78,7 @@ class Application : public Runtime::Observer,
// immediately after its termination.
void Terminate();

const std::vector<Runtime*>& runtimes() const { return runtimes_.get(); }
const std::vector<XWalkContent*>& pages() const { return pages_.get(); }

// Returns the unique application id which is used to distinguish the
// application amoung both running applications and installed ones
Expand All @@ -93,7 +94,7 @@ class Application : public Runtime::Observer,
// Tells whether the application use the specified extension.
bool UseExtension(const std::string& extension_name) const;

// The runtime permission mapping is registered by extension which
// The content permission mapping is registered by extension which
// implements some specific API, for example:
// "bluetooth" -> "bluetooth.read, bluetooth.write, bluetooth.management"
// Whenever there comes a API permission request, we can tell whether
Expand Down Expand Up @@ -122,16 +123,16 @@ class Application : public Runtime::Observer,
virtual bool Launch(const LaunchParams& launch_params);
virtual void InitSecurityPolicy();

// Runtime::Observer implementation.
virtual void OnNewRuntimeAdded(Runtime* runtime) override;
virtual void OnRuntimeClosed(Runtime* runtime) override;
// XWalkContent::Observer implementation.
virtual void OnContentCreated(XWalkContent* content) override;
virtual void OnContentClosed(XWalkContent* content) override;

// Get the path of splash screen image. Return empty path by default.
// Sub class can override it to return a specific path.
virtual base::FilePath GetSplashScreenPath();

XWalkBrowserContext* browser_context_;
ScopedVector<Runtime> runtimes_;
ScopedVector<XWalkContent> pages_;
scoped_refptr<ApplicationData> const data_;
// The application's render process host.
content::RenderProcessHost* render_process_host_;
Expand Down
2 changes: 1 addition & 1 deletion application/browser/application_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "xwalk/application/common/application_manifest_constants.h"
#include "xwalk/application/common/application_file_util.h"
#include "xwalk/application/common/id_util.h"
#include "xwalk/runtime/browser/runtime.h"
#include "xwalk/runtime/browser/xwalk_content.h"
#include "xwalk/runtime/browser/xwalk_browser_context.h"
#include "xwalk/runtime/common/xwalk_paths.h"

Expand Down
75 changes: 36 additions & 39 deletions application/browser/application_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ namespace application {
const char kDefaultMediaAppClass[] = "player";
namespace {
#if defined(OS_TIZEN_MOBILE)
void ApplyRootWindowParams(Runtime* runtime,
void ApplyRootWindowParams(XWalkContent* content,
NativeAppWindow::CreateParams* params) {
if (!params->delegate)
params->delegate = runtime;
params->delegate = content;
if (params->bounds.IsEmpty())
params->bounds = gfx::Rect(0, 0, 840, 600);

unsigned int fullscreen_options = runtime->fullscreen_options();
unsigned int fullscreen_options = content->fullscreen_options();
if (params->state == ui::SHOW_STATE_FULLSCREEN)
fullscreen_options |= Runtime::FULLSCREEN_FOR_LAUNCH;
fullscreen_options |= XWalkContent::FULLSCREEN_FOR_LAUNCH;
else
fullscreen_options &= ~Runtime::FULLSCREEN_FOR_LAUNCH;
runtime->set_fullscreen_options(fullscreen_options);
content->set_fullscreen_options(fullscreen_options);
}

NativeAppWindow* CreateRootWindow(Runtime* runtime,
NativeAppWindow* CreateRootWindow(XWalkContent* content,
const NativeAppWindow::CreateParams& params) {
NativeAppWindow::CreateParams effective_params(params);
ApplyRootWindowParams(runtime, &effective_params);
ApplyRootWindowParams(content, &effective_params);
return NativeAppWindow::Create(effective_params);
}
#endif
Expand Down Expand Up @@ -109,11 +109,11 @@ class ScreenOrientationProviderTizen :
return;
}
request_id_ = request_id;
const std::vector<Runtime*>& runtimes = app_->runtimes();
DCHECK(!runtimes.empty());
const std::vector<XWalkContent*>& pages = app_->pages();
DCHECK(!pages.empty());
// FIXME: Probably need better alignment with
// https://w3c.github.io/screen-orientation/#screen-orientation-lock-lifetime
for (auto it = runtimes.begin(); it != runtimes.end(); ++it) {
for (auto it = pages.begin(); it != pages.end(); ++it) {
NativeAppWindow* window = (*it)->window();
if (window && window->IsActive()) {
ToNativeAppWindowTizen(window)->LockOrientation(lock);
Expand Down Expand Up @@ -157,26 +157,26 @@ ApplicationTizen::~ApplicationTizen() {
}

void ApplicationTizen::Hide() {
DCHECK(!runtimes_.empty());
for (auto it = runtimes_.begin(); it != runtimes_.end(); ++it) {
if ((*it)->window())
(*it)->window()->Minimize();
DCHECK(!pages_.empty());
for (XWalkContent* page : pages_) {
if (auto window = page->window())
window->Minimize();
}
}

void ApplicationTizen::Show() {
DCHECK(!runtimes_.empty());
for (Runtime* runtime : runtimes_) {
if (auto window = runtime->window())
DCHECK(!pages_.empty());
for (XWalkContent* page : pages_) {
if (auto window = page->window())
window->Restore();
}
}

bool ApplicationTizen::Launch(const LaunchParams& launch_params) {
if (Application::Launch(launch_params)) {
#if defined(OS_TIZEN_MOBILE)
if (!runtimes_.empty()) {
root_window_ = CreateRootWindow(*(runtimes_.begin()),
if (!pages_.empty()) {
root_window_ = CreateRootWindow(*(pages_.begin()),
window_show_params_);
window_show_params_.parent = root_window_->GetNativeWindow();
root_window_->Show();
Expand Down Expand Up @@ -234,10 +234,9 @@ void ApplicationTizen::Suspend() {
DCHECK(render_process_host_);
render_process_host_->Send(new ViewMsg_SuspendJSEngine(true));

DCHECK(!runtimes_.empty());
for (auto it = runtimes_.begin(); it != runtimes_.end(); ++it) {
if ((*it)->web_contents())
(*it)->web_contents()->WasHidden();
DCHECK(!pages_.empty());
for (XWalkContent* page : pages_) {
page->web_contents()->WasHidden();
}
is_suspended_ = true;
}
Expand All @@ -249,10 +248,9 @@ void ApplicationTizen::Resume() {
DCHECK(render_process_host_);
render_process_host_->Send(new ViewMsg_SuspendJSEngine(false));

DCHECK(!runtimes_.empty());
for (auto it = runtimes_.begin(); it != runtimes_.end(); ++it) {
if ((*it)->web_contents())
(*it)->web_contents()->WasShown();
DCHECK(!pages_.empty());
for (XWalkContent* page : pages_) {
page->web_contents()->WasShown();
}
is_suspended_ = false;
}
Expand Down Expand Up @@ -282,10 +280,9 @@ void ApplicationTizen::DidProcessEvent(
if (info && !info->hwkey_enabled())
return;

for (auto it = runtimes_.begin();
it != runtimes_.end(); ++it) {
(*it)->web_contents()->GetRenderViewHost()->Send(new ViewMsg_HWKeyPressed(
(*it)->web_contents()->GetRoutingID(), key_event->key_code()));
for (XWalkContent* page : pages_) {
page->web_contents()->GetRenderViewHost()->Send(new ViewMsg_HWKeyPressed(
page->web_contents()->GetRoutingID(), key_event->key_code()));
}
}
#endif
Expand All @@ -299,20 +296,20 @@ void ApplicationTizen::SetUserAgentString(
cookie_manager_->SetUserAgentString(render_process_host_, user_agent_string);
}

void ApplicationTizen::OnNewRuntimeAdded(Runtime* runtime) {
DCHECK(runtime);
Application::OnNewRuntimeAdded(runtime);
void ApplicationTizen::OnContentCreated(XWalkContent* content) {
DCHECK(content);
Application::OnContentCreated(content);
#if defined(OS_TIZEN_MOBILE)
if (root_window_ && runtimes_.size() > 1)
if (root_window_ && pages_.size() > 1)
root_window_->Show();
#endif
}

void ApplicationTizen::OnRuntimeClosed(Runtime* runtime) {
DCHECK(runtime);
Application::OnRuntimeClosed(runtime);
void ApplicationTizen::OnContentClosed(XWalkContent* content) {
DCHECK(content);
Application::OnContentClosed(content);
#if defined(OS_TIZEN_MOBILE)
if (runtimes_.empty() && root_window_) {
if (pages_.empty() && root_window_) {
root_window_->Close();
root_window_ = NULL;
}
Expand Down
6 changes: 3 additions & 3 deletions application/browser/application_tizen.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class ApplicationTizen : // NOLINT

virtual base::FilePath GetSplashScreenPath() OVERRIDE;

// Runtime::Observer implementation.
virtual void OnNewRuntimeAdded(Runtime* runtime) OVERRIDE;
virtual void OnRuntimeClosed(Runtime* runtime) OVERRIDE;
// XWalkContent::Observer implementation.
virtual void OnContentCreated(XWalkContent* content) OVERRIDE;
virtual void OnContentClosed(XWalkContent* content) OVERRIDE;

#if defined(USE_OZONE)
virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE;
Expand Down
2 changes: 1 addition & 1 deletion application/extension/application_runtime_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "ui/base/resource/resource_bundle.h"
#include "xwalk/application/browser/application.h"
#include "xwalk/application/common/application_data.h"
#include "xwalk/runtime/browser/runtime.h"
#include "xwalk/runtime/browser/xwalk_content.h"

using content::BrowserThread;

Expand Down
2 changes: 1 addition & 1 deletion application/extension/application_widget_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "xwalk/application/common/application_manifest_constants.h"
#include "xwalk/application/common/manifest_handlers/widget_handler.h"
#include "xwalk/application/extension/application_widget_storage.h"
#include "xwalk/runtime/browser/runtime.h"
#include "xwalk/runtime/browser/xwalk_content.h"
#include "xwalk/runtime/browser/xwalk_browser_context.h"
#include "xwalk/runtime/browser/xwalk_runner.h"
#include "xwalk/runtime/common/xwalk_paths.h"
Expand Down
4 changes: 2 additions & 2 deletions application/test/application_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ IN_PROC_BROWSER_TEST_F(ApplicationTest, TestMultiApp) {
test_runner_->WaitForTestNotification();
EXPECT_EQ(test_runner_->GetTestsResult(), ApiTestRunner::PASS);
// The App1 has 2 pages: main doc page and "main.html" page.
EXPECT_EQ(app1->runtimes().size(), 1);
EXPECT_EQ(app1->pages().size(), 1);

EXPECT_EQ(service->active_applications().size(), currently_running_count + 1);
EXPECT_EQ(service->GetApplicationByID(app1->id()), app1);
Expand All @@ -59,7 +59,7 @@ IN_PROC_BROWSER_TEST_F(ApplicationTest, TestMultiApp) {
EXPECT_EQ(test_runner_->GetTestsResult(), ApiTestRunner::PASS);

// The App2 also has 2 pages: main doc page and "main.html" page.
EXPECT_EQ(app2->runtimes().size(), 1);
EXPECT_EQ(app2->pages().size(), 1);

// Check that the apps have different IDs and RPH IDs.
EXPECT_NE(app1->id(), app2->id());
Expand Down
Loading

0 comments on commit 0ca4a32

Please sign in to comment.