Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / first_run / first_run_view.cc
1 // Copyright 2013 The Chromium Authors. 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 "chrome/browser/chromeos/first_run/first_run_view.h"
6
7 #include "chrome/browser/extensions/extension_web_contents_observer.h"
8 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_ui.h"
9 #include "chrome/common/url_constants.h"
10 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/render_widget_host_view.h"
12 #include "content/public/browser/web_contents.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "ui/views/controls/webview/webview.h"
16 #include "url/gurl.h"
17
18 namespace chromeos {
19
20 FirstRunView::FirstRunView()
21     : web_view_(NULL) {
22 }
23
24 void FirstRunView::Init(content::BrowserContext* context) {
25   web_view_ = new views::WebView(context);
26   AddChildView(web_view_);
27   web_view_->LoadInitialURL(GURL(chrome::kChromeUIFirstRunURL));
28
29   content::WebContents* web_contents = web_view_->web_contents();
30   web_contents->SetDelegate(this);
31   extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents);
32
33   SkBitmap background;
34   background.setConfig(SkBitmap::kA8_Config, 1, 1);
35   background.allocPixels();
36   background.eraseARGB(0, 0, 0, 0);
37   web_contents->GetRenderViewHost()->GetView()->
38     SetBackground(background);
39 }
40
41 FirstRunActor* FirstRunView::GetActor() {
42   return static_cast<FirstRunUI*>(
43       web_view_->web_contents()->GetWebUI()->GetController())->get_actor();
44 }
45
46 void FirstRunView::Layout() {
47   web_view_->SetBoundsRect(bounds());
48 }
49
50 void FirstRunView::RequestFocus() {
51   web_view_->RequestFocus();
52 }
53
54 content::WebContents* FirstRunView::GetWebContents() {
55   return web_view_->web_contents();
56 }
57
58 bool FirstRunView::HandleContextMenu(
59     const content::ContextMenuParams& params) {
60   // Discards context menu.
61   return true;
62 }
63
64 bool FirstRunView::PreHandleGestureEvent(
65     content::WebContents* source,
66     const blink::WebGestureEvent& event) {
67   // Disable pinch zooming.
68   return event.type == blink::WebGestureEvent::GesturePinchBegin ||
69       event.type == blink::WebGestureEvent::GesturePinchUpdate ||
70       event.type == blink::WebGestureEvent::GesturePinchEnd;
71 }
72
73 }  // namespace chromeos
74