1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/application/browser/application_tizen.h"
11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/render_process_host.h"
14 #include "xwalk/runtime/browser/ui/native_app_window.h"
15 #include "xwalk/runtime/common/xwalk_common_messages.h"
17 #if defined(USE_OZONE)
18 #include "base/message_loop/message_pump_ozone.h"
19 #include "content/public/browser/render_view_host.h"
20 #include "ui/events/event.h"
21 #include "ui/events/event_constants.h"
22 #include "ui/events/keycodes/keyboard_codes_posix.h"
23 #include "xwalk/application/common/manifest_handlers/tizen_setting_handler.h"
26 #include "xwalk/application/common/application_manifest_constants.h"
27 #include "xwalk/application/common/manifest_handlers/navigation_handler.h"
31 namespace widget_keys = application_widget_keys;
33 namespace application {
36 const char kAsterisk[] = "*";
40 ApplicationTizen::ApplicationTizen(
41 scoped_refptr<ApplicationData> data,
42 RuntimeContext* runtime_context,
43 Application::Observer* observer)
44 : Application(data, runtime_context, observer) {
45 #if defined(USE_OZONE)
46 base::MessagePumpOzone::Current()->AddObserver(this);
50 ApplicationTizen::~ApplicationTizen() {
51 #if defined(USE_OZONE)
52 base::MessagePumpOzone::Current()->RemoveObserver(this);
56 void ApplicationTizen::Hide() {
57 DCHECK(runtimes_.size());
58 std::set<Runtime*>::iterator it = runtimes_.begin();
59 for (; it != runtimes_.end(); ++it) {
61 (*it)->window()->Hide();
65 void ApplicationTizen::InitSecurityPolicy() {
66 // On Tizen, CSP mode has higher priority, and WARP will be disabled
67 // if the application is under CSP mode.
68 if (!application_data_->HasCSPDefined()) {
69 Application::InitSecurityPolicy();
73 if (application_data_->GetPackageType() != Manifest::TYPE_WGT)
76 // Always enable security mode when under CSP mode.
77 is_security_mode_ = true;
78 NavigationInfo* info = static_cast<NavigationInfo*>(
79 application_data_->GetManifestData(widget_keys::kAllowNavigationKey));
81 const std::vector<std::string>& allowed_list = info->GetAllowedDomains();
82 for (std::vector<std::string>::const_iterator it = allowed_list.begin();
83 it != allowed_list.end(); ++it) {
84 // If the policy is "*", it represents that any external link is allowed
86 if ((*it) == kAsterisk) {
87 is_security_mode_ = false;
91 // If the policy start with "*.", like this: *.domain,
92 // means that can access to all subdomains for 'domain',
93 // otherwise, the host of request url should exactly the same
95 bool subdomains = ((*it).find("*.") == 0);
96 std::string host = subdomains ? (*it).substr(2) : (*it);
97 AddSecurityPolicy(GURL("http://" + host), subdomains);
98 AddSecurityPolicy(GURL("https://" + host), subdomains);
101 main_runtime_->GetRenderProcessHost()->Send(
102 new ViewMsg_EnableSecurityMode(
103 ApplicationData::GetBaseURLFromApplicationId(id()),
104 SecurityPolicy::CSP));
107 #if defined(USE_OZONE)
108 base::EventStatus ApplicationTizen::WillProcessEvent(
109 const base::NativeEvent& event) {
110 return base::EVENT_CONTINUE;
113 void ApplicationTizen::DidProcessEvent(
114 const base::NativeEvent& event) {
115 ui::Event* ui_event = static_cast<ui::Event*>(event);
116 if (!ui_event->IsKeyEvent() || ui_event->type() != ui::ET_KEY_PRESSED)
119 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event);
121 // FIXME: Most Wayland devices don't have similar hardware button for 'back'
122 // and 'memu' as Tizen Mobile, even that hardare buttons could be different
123 // across different kinds of Wayland platforms.
124 // Here use external keyboard button 'Backspace' & 'HOME' to emulate 'back'
125 // and 'menu' key. Should change this if there is customized key binding.
126 if (key_event->key_code() != ui::VKEY_BACK &&
127 key_event->key_code() != ui::VKEY_HOME)
130 TizenSettingInfo* info = static_cast<TizenSettingInfo*>(
131 data()->GetManifestData(widget_keys::kTizenSettingKey));
132 if (info && !info->hwkey_enabled())
135 for (std::set<xwalk::Runtime*>::iterator it = runtimes_.begin();
136 it != runtimes_.end(); ++it) {
137 (*it)->web_contents()->GetRenderViewHost()->Send(new ViewMsg_HWKeyPressed(
138 (*it)->web_contents()->GetRoutingID(), key_event->key_code()));
143 } // namespace application