Chromium Code Reviews| Index: apps/custom_launcher_page_contents.cc |
| diff --git a/apps/custom_launcher_page_contents.cc b/apps/custom_launcher_page_contents.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba1bd981a104ebdb10d4e36a1fd49a7e024bf52b |
| --- /dev/null |
| +++ b/apps/custom_launcher_page_contents.cc |
| @@ -0,0 +1,84 @@ |
| +// 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) { |
| + url_ = 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_)))); |
| + |
| + content::WebContentsObserver::Observe(web_contents_.get()); |
|
tapted
2014/07/10 04:29:34
nit: omit content::WebContentsObserver:: ?
Matt Giuca
2014/07/10 07:37:03
Done.
|
| + 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_.get()); |
| +} |
| + |
| +void CustomLauncherPageContents::LoadContents() { |
| + web_contents_->GetController().LoadURL(url_, |
| + content::Referrer(), |
| + content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| + std::string()); |
| +} |
| + |
| +content::WebContents* CustomLauncherPageContents::GetWebContents() const { |
| + return web_contents_.get(); |
| +} |
| + |
| +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_.get(); |
| +} |
| + |
| +void CustomLauncherPageContents::OnRequest( |
| + const ExtensionHostMsg_Request_Params& params) { |
| + extension_function_dispatcher_->Dispatch(params, |
| + web_contents_->GetRenderViewHost()); |
| +} |
| + |
| +} // namespace apps |