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.
5 #include "apps/shell/browser/shell_app_window.h"
7 #include "apps/shell/browser/shell_extension_web_contents_observer.h"
8 #include "content/public/browser/navigation_controller.h"
9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_contents.h"
11 #include "extensions/browser/view_type_utils.h"
12 #include "extensions/common/extension_messages.h"
13 #include "ipc/ipc_message_macros.h"
15 using content::BrowserContext
;
16 using content::WebContents
;
20 ShellAppWindow::ShellAppWindow() {}
22 ShellAppWindow::~ShellAppWindow() {}
24 void ShellAppWindow::Init(BrowserContext
* context
, gfx::Size initial_size
) {
25 extension_function_dispatcher_
.reset(
26 new extensions::ExtensionFunctionDispatcher(context
, this));
28 // Create the web contents with an initial size to avoid a resize.
29 WebContents::CreateParams
create_params(context
);
30 create_params
.initial_size
= initial_size
;
31 web_contents_
.reset(WebContents::Create(create_params
));
33 content::WebContentsObserver::Observe(web_contents_
.get());
35 // Add support for extension startup.
36 extensions::ShellExtensionWebContentsObserver::CreateForWebContents(
39 extensions::SetViewType(web_contents_
.get(),
40 extensions::VIEW_TYPE_APP_WINDOW
);
43 void ShellAppWindow::LoadURL(const GURL
& url
) {
44 content::NavigationController::LoadURLParams
params(url
);
45 web_contents_
->GetController().LoadURLWithParams(params
);
46 web_contents_
->Focus();
49 aura::Window
* ShellAppWindow::GetNativeWindow() {
50 return web_contents_
->GetNativeView();
53 int ShellAppWindow::GetRenderViewRoutingID() {
54 return web_contents_
->GetRenderViewHost()->GetRoutingID();
57 bool ShellAppWindow::OnMessageReceived(const IPC::Message
& message
) {
59 IPC_BEGIN_MESSAGE_MAP(ShellAppWindow
, message
)
60 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request
, OnRequest
)
61 IPC_MESSAGE_UNHANDLED(handled
= false)
66 content::WebContents
* ShellAppWindow::GetAssociatedWebContents() const {
67 return web_contents_
.get();
70 void ShellAppWindow::OnRequest(const ExtensionHostMsg_Request_Params
& params
) {
71 extension_function_dispatcher_
->Dispatch(params
,
72 web_contents_
->GetRenderViewHost());