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/custom_launcher_page_contents.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/site_instance.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/renderer_preferences.h"
16 #include "extensions/common/extension_messages.h"
20 CustomLauncherPageContents::CustomLauncherPageContents() {
23 CustomLauncherPageContents::~CustomLauncherPageContents() {
26 void CustomLauncherPageContents::Initialize(content::BrowserContext
* context
,
28 extension_function_dispatcher_
.reset(
29 new extensions::ExtensionFunctionDispatcher(context
, this));
32 content::WebContents::Create(content::WebContents::CreateParams(
33 context
, content::SiteInstance::CreateForURL(context
, url
))));
35 Observe(web_contents());
36 web_contents_
->GetMutableRendererPrefs()
37 ->browser_handles_all_top_level_requests
= true;
38 web_contents_
->GetRenderViewHost()->SyncRendererPrefs();
40 // This observer will activate the extension when it is navigated to, which
41 // allows Dispatcher to give it the proper context and makes it behave like an
43 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
46 web_contents_
->GetController().LoadURL(url
,
48 content::PAGE_TRANSITION_AUTO_TOPLEVEL
,
52 bool CustomLauncherPageContents::OnMessageReceived(
53 const IPC::Message
& message
) {
55 IPC_BEGIN_MESSAGE_MAP(CustomLauncherPageContents
, message
)
56 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request
, OnRequest
)
57 IPC_MESSAGE_UNHANDLED(handled
= false)
62 extensions::WindowController
*
63 CustomLauncherPageContents::GetExtensionWindowController() const {
67 content::WebContents
* CustomLauncherPageContents::GetAssociatedWebContents()
69 return web_contents();
72 void CustomLauncherPageContents::OnRequest(
73 const ExtensionHostMsg_Request_Params
& params
) {
74 extension_function_dispatcher_
->Dispatch(params
,
75 web_contents_
->GetRenderViewHost());