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.
5 #include "xwalk/runtime/browser/runtime_ui_strategy.h"
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"
17 #if !defined(OS_ANDROID)
18 // The default size for web content area size.
19 const int kDefaultWidth = 840;
20 const int kDefaultHeight = 600;
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);
31 unsigned int fullscreen_options = runtime->fullscreen_options();
32 if (params->state == ui::SHOW_STATE_FULLSCREEN)
33 fullscreen_options |= Runtime::FULLSCREEN_FOR_LAUNCH;
35 fullscreen_options &= ~Runtime::FULLSCREEN_FOR_LAUNCH;
36 runtime->set_fullscreen_options(fullscreen_options);
41 RuntimeUIStrategy::RuntimeUIStrategy() {}
43 RuntimeUIStrategy::~RuntimeUIStrategy() {}
45 void RuntimeUIStrategy::Show(
46 Runtime* runtime, const NativeAppWindow::CreateParams& params) {
47 #if defined(OS_ANDROID)
50 NativeAppWindow::CreateParams effective_params(params);
51 ApplyWindowDefaultParams(runtime, &effective_params);
53 // Set the app icon if it is passed from command line.
54 CommandLine* command_line = CommandLine::ForCurrentProcess();
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);
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);
66 runtime->EnableTitleUpdatedNotification();
68 NativeAppWindow* window = NativeAppWindow::Create(effective_params);
69 runtime->set_window(window);
71 runtime->set_app_icon(app_icon);