Upstream version 5.34.104.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   const char* gl_name;
38   if (base::PathExists(base::FilePath("/usr/lib/libGL.so")))
39     gl_name = gfx::kGLImplementationDesktopName;
40   else
41     gl_name = gfx::kGLImplementationEGLName;
42   command_line->AppendSwitchASCII(switches::kUseGL, gl_name);
43
44   XWalkBrowserMainParts::PreMainMessageLoopStart();
45 }
46
47 void XWalkBrowserMainPartsTizen::PreMainMessageLoopRun() {
48   if (content::DeviceInertialSensorService* sensor_service =
49           content::DeviceInertialSensorService::GetInstance()) {
50     // As the data fetcher of sensors is implemented outside of Chromium, we
51     // need to make it available to Chromium by "abusing" the test framework.
52     // TODO(zliang7): Find a decent way to inject our sensor fetcher for Tizen.
53     sensor_service->SetDataFetcherForTests(new TizenDataFetcherSharedMemory());
54   }
55
56   XWalkBrowserMainParts::PreMainMessageLoopRun();
57 }
58
59 // static.
60 OrientationMask XWalkBrowserMainPartsTizen::GetAllowedUAOrientations() {
61   char* env = getenv("TIZEN_ALLOWED_ORIENTATIONS");
62   int value = env ? atoi(env) : 0;
63   if (value > 0 && value < (1 << 4))
64     return static_cast<OrientationMask>(value);
65
66   // Tizen mobile supports all orientations by default.
67   return ANY;
68 }
69
70 void XWalkBrowserMainPartsTizen::CreateInternalExtensionsForUIThread(
71     content::RenderProcessHost* host,
72     extensions::XWalkExtensionVector* extensions) {
73   XWalkBrowserMainParts::CreateInternalExtensionsForUIThread(
74       host, extensions);
75   // FIXME(Mikhail): move this code to a dedicated XWalkComponent.
76   application::ApplicationSystem* app_system = xwalk_runner_->app_system();
77   application::ApplicationService* app_service
78       = app_system->application_service();
79   Application* application =
80       app_service->GetApplicationByRenderHostID(host->GetID());
81   if (!application)
82     return;
83   extensions->push_back(new ScreenOrientationExtension(
84         application, GetAllowedUAOrientations()));
85 }
86
87 }  // namespace xwalk