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/runtime/browser/xwalk_browser_main_parts_tizen.h"
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"
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"
26 using application::Application;
28 XWalkBrowserMainPartsTizen::XWalkBrowserMainPartsTizen(
29 const content::MainFunctionParams& parameters)
30 : XWalkBrowserMainParts(parameters) {
33 void XWalkBrowserMainPartsTizen::PreMainMessageLoopStart() {
34 CommandLine* command_line = CommandLine::ForCurrentProcess();
35 command_line->AppendSwitch(switches::kIgnoreGpuBlacklist);
38 if (base::PathExists(base::FilePath("/usr/lib/libGL.so")))
39 gl_name = gfx::kGLImplementationDesktopName;
41 gl_name = gfx::kGLImplementationEGLName;
42 command_line->AppendSwitchASCII(switches::kUseGL, gl_name);
44 XWalkBrowserMainParts::PreMainMessageLoopStart();
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());
56 XWalkBrowserMainParts::PreMainMessageLoopRun();
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);
66 // Tizen mobile supports all orientations by default.
70 void XWalkBrowserMainPartsTizen::CreateInternalExtensionsForUIThread(
71 content::RenderProcessHost* host,
72 extensions::XWalkExtensionVector* extensions) {
73 XWalkBrowserMainParts::CreateInternalExtensionsForUIThread(
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());
83 extensions->push_back(new ScreenOrientationExtension(
84 application, GetAllowedUAOrientations()));