a2de96caca4da968f45e40fdc8f47e5929b3ccb8
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / runtime_ui_strategy.cc
1 // Copyright (c) 2014 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/runtime_ui_strategy.h"
6
7 #include "base/command_line.h"
8 #include "grit/xwalk_resources.h"
9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/image/image.h"
11 #include "xwalk/runtime/browser/image_util.h"
12 #include "xwalk/runtime/browser/runtime.h"
13 #include "xwalk/runtime/common/xwalk_switches.h"
14
15 namespace xwalk {
16 namespace {
17 #if !defined(OS_ANDROID)
18 // The default size for web content area size.
19 const int kDefaultWidth = 840;
20 const int kDefaultHeight = 600;
21
22 void ApplyWindowDefaultParams(Runtime* runtime,
23                               NativeAppWindow::CreateParams* params) {
24   if (!params->delegate)
25     params->delegate = runtime;
26   if (!params->web_contents)
27     params->web_contents = runtime->web_contents();
28   if (params->bounds.IsEmpty())
29     params->bounds = gfx::Rect(0, 0, kDefaultWidth, kDefaultHeight);
30
31   unsigned int fullscreen_options = runtime->fullscreen_options();
32   if (params->state == ui::SHOW_STATE_FULLSCREEN)
33     fullscreen_options |= Runtime::FULLSCREEN_FOR_LAUNCH;
34   else
35     fullscreen_options &= ~Runtime::FULLSCREEN_FOR_LAUNCH;
36   runtime->set_fullscreen_options(fullscreen_options);
37 }
38 #endif
39 }  // namespace
40
41 RuntimeUIStrategy::RuntimeUIStrategy() {}
42
43 RuntimeUIStrategy::~RuntimeUIStrategy() {}
44
45 void RuntimeUIStrategy::Show(
46     Runtime* runtime, const NativeAppWindow::CreateParams& params) {
47 #if defined(OS_ANDROID)
48   NOTIMPLEMENTED();
49 #else
50   NativeAppWindow::CreateParams effective_params(params);
51   ApplyWindowDefaultParams(runtime, &effective_params);
52
53   // Set the app icon if it is passed from command line.
54   CommandLine* command_line = CommandLine::ForCurrentProcess();
55   gfx::Image app_icon;
56   if (command_line->HasSwitch(switches::kAppIcon)) {
57     base::FilePath icon_file =
58         command_line->GetSwitchValuePath(switches::kAppIcon);
59     app_icon = xwalk_utils::LoadImageFromFilePath(icon_file);
60   } else {
61     // Otherwise, use the default icon for Crosswalk app.
62     ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
63     app_icon = rb.GetNativeImageNamed(IDR_XWALK_ICON_48);
64   }
65
66   runtime->EnableTitleUpdatedNotification();
67
68   NativeAppWindow* window = NativeAppWindow::Create(effective_params);
69   runtime->set_window(window);
70
71   runtime->set_app_icon(app_icon);
72   window->Show();
73 #endif
74 }
75 }  // namespace xwalk