Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / xwalk_browser_main_parts_tizen.cc
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.
4
5 #include "xwalk/runtime/browser/xwalk_browser_main_parts_tizen.h"
6
7 #include "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "content/public/browser/render_process_host.h"
10 #include "content/public/common/content_switches.h"
11 #include "xwalk/application/browser/application.h"
12 #include "xwalk/application/browser/application_service.h"
13 #include "xwalk/application/browser/application_system.h"
14 #include "xwalk/extensions/common/xwalk_extension.h"
15 #include "xwalk/runtime/browser/xwalk_runner.h"
16 #include "xwalk/runtime/common/xwalk_runtime_features.h"
17 #include "ui/gl/gl_switches.h"
18 #include "ui/gfx/switches.h"
19
20 #include "content/browser/device_orientation/device_inertial_sensor_service.h"
21 #include "xwalk/runtime/extension/screen_orientation_extension.h"
22 #include "xwalk/tizen/mobile/sensor/tizen_data_fetcher_shared_memory.h"
23
24 namespace xwalk {
25
26 using application::Application;
27
28 XWalkBrowserMainPartsTizen::XWalkBrowserMainPartsTizen(
29     const content::MainFunctionParams& parameters)
30     : XWalkBrowserMainParts(parameters) {
31 }
32
33 void XWalkBrowserMainPartsTizen::PreMainMessageLoopStart() {
34   CommandLine* command_line = CommandLine::ForCurrentProcess();
35   command_line->AppendSwitch(switches::kIgnoreGpuBlacklist);
36
37   // Enable Accelerated 2D Canvas.
38   command_line->AppendSwitch(switches::kGpuNoContextLost);
39
40   const char* gl_name;
41   if (base::PathExists(base::FilePath("/usr/lib/libGL.so")))
42     gl_name = gfx::kGLImplementationDesktopName;
43   else
44     gl_name = gfx::kGLImplementationEGLName;
45   command_line->AppendSwitchASCII(switches::kUseGL, gl_name);
46
47   XWalkBrowserMainParts::PreMainMessageLoopStart();
48 }
49
50 void XWalkBrowserMainPartsTizen::PreMainMessageLoopRun() {
51   if (content::DeviceInertialSensorService* sensor_service =
52           content::DeviceInertialSensorService::GetInstance()) {
53     // As the data fetcher of sensors is implemented outside of Chromium, we
54     // need to make it available to Chromium by "abusing" the test framework.
55     // TODO(zliang7): Find a decent way to inject our sensor fetcher for Tizen.
56     sensor_service->SetDataFetcherForTests(new TizenDataFetcherSharedMemory());
57   }
58
59   XWalkBrowserMainParts::PreMainMessageLoopRun();
60 }
61
62 // static.
63 OrientationMask XWalkBrowserMainPartsTizen::GetAllowedUAOrientations() {
64   char* env = getenv("TIZEN_ALLOWED_ORIENTATIONS");
65   int value = env ? atoi(env) : 0;
66   if (value > 0 && value < (1 << 4))
67     return static_cast<OrientationMask>(value);
68
69   // Tizen mobile supports all orientations by default.
70   return ANY;
71 }
72
73 void XWalkBrowserMainPartsTizen::CreateInternalExtensionsForUIThread(
74     content::RenderProcessHost* host,
75     extensions::XWalkExtensionVector* extensions) {
76   XWalkBrowserMainParts::CreateInternalExtensionsForUIThread(
77       host, extensions);
78   // FIXME(Mikhail): move this code to a dedicated XWalkComponent.
79   application::ApplicationSystem* app_system = xwalk_runner_->app_system();
80   application::ApplicationService* app_service
81       = app_system->application_service();
82   Application* application =
83       app_service->GetApplicationByRenderHostID(host->GetID());
84   if (!application)
85     return;
86   extensions->push_back(new ScreenOrientationExtension(
87         application, GetAllowedUAOrientations()));
88 }
89
90 }  // namespace xwalk