Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / extensions / shell / browser / shell_app_window.cc
1 // Copyright 2014 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 "extensions/shell/browser/shell_app_window.h"
6
7 #include "content/public/browser/navigation_controller.h"
8 #include "content/public/browser/render_view_host.h"
9 #include "content/public/browser/web_contents.h"
10 #include "extensions/browser/view_type_utils.h"
11 #include "extensions/common/extension_messages.h"
12 #include "extensions/shell/browser/shell_extension_web_contents_observer.h"
13 #include "ipc/ipc_message_macros.h"
14
15 using content::BrowserContext;
16 using content::WebContents;
17
18 namespace extensions {
19
20 ShellAppWindow::ShellAppWindow() {
21 }
22
23 ShellAppWindow::~ShellAppWindow() {
24 }
25
26 void ShellAppWindow::Init(BrowserContext* context, gfx::Size initial_size) {
27   extension_function_dispatcher_.reset(
28       new ExtensionFunctionDispatcher(context, this));
29
30   // Create the web contents with an initial size to avoid a resize.
31   WebContents::CreateParams create_params(context);
32   create_params.initial_size = initial_size;
33   web_contents_.reset(WebContents::Create(create_params));
34
35   content::WebContentsObserver::Observe(web_contents_.get());
36
37   // Add support for extension startup.
38   ShellExtensionWebContentsObserver::CreateForWebContents(web_contents_.get());
39
40   SetViewType(web_contents_.get(), VIEW_TYPE_APP_WINDOW);
41 }
42
43 void ShellAppWindow::LoadURL(const GURL& url) {
44   content::NavigationController::LoadURLParams params(url);
45   web_contents_->GetController().LoadURLWithParams(params);
46   web_contents_->Focus();
47 }
48
49 aura::Window* ShellAppWindow::GetNativeWindow() {
50   return web_contents_->GetNativeView();
51 }
52
53 int ShellAppWindow::GetRenderViewRoutingID() {
54   return web_contents_->GetRenderViewHost()->GetRoutingID();
55 }
56
57 bool ShellAppWindow::OnMessageReceived(const IPC::Message& message) {
58   bool handled = true;
59   IPC_BEGIN_MESSAGE_MAP(ShellAppWindow, message)
60   IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
61   IPC_MESSAGE_UNHANDLED(handled = false)
62   IPC_END_MESSAGE_MAP()
63   return handled;
64 }
65
66 content::WebContents* ShellAppWindow::GetAssociatedWebContents() const {
67   return web_contents_.get();
68 }
69
70 void ShellAppWindow::OnRequest(const ExtensionHostMsg_Request_Params& params) {
71   extension_function_dispatcher_->Dispatch(params,
72                                            web_contents_->GetRenderViewHost());
73 }
74
75 }  // namespace extensions