blob: 896d9da5e683abdea3572bc840f358f223e73d33 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "apps/custom_launcher_page_contents.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/renderer_preferences.h"
#include "extensions/common/extension_messages.h"
namespace apps {
CustomLauncherPageContents::CustomLauncherPageContents() {
}
CustomLauncherPageContents::~CustomLauncherPageContents() {
}
void CustomLauncherPageContents::Initialize(content::BrowserContext* context,
const GURL& url) {
extension_function_dispatcher_.reset(
new extensions::ExtensionFunctionDispatcher(context, this));
web_contents_.reset(
content::WebContents::Create(content::WebContents::CreateParams(
context, content::SiteInstance::CreateForURL(context, url))));
Observe(web_contents());
web_contents_->GetMutableRendererPrefs()
->browser_handles_all_top_level_requests = true;
web_contents_->GetRenderViewHost()->SyncRendererPrefs();
// This observer will activate the extension when it is navigated to, which
// allows Dispatcher to give it the proper context and makes it behave like an
// extension.
extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
web_contents());
web_contents_->GetController().LoadURL(url,
content::Referrer(),
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string());
}
bool CustomLauncherPageContents::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(CustomLauncherPageContents, message)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
extensions::WindowController*
CustomLauncherPageContents::GetExtensionWindowController() const {
return NULL;
}
content::WebContents* CustomLauncherPageContents::GetAssociatedWebContents()
const {
return web_contents();
}
void CustomLauncherPageContents::OnRequest(
const ExtensionHostMsg_Request_Params& params) {
extension_function_dispatcher_->Dispatch(params,
web_contents_->GetRenderViewHost());
}
} // namespace apps
|