OLD | NEW |
(Empty) | |
| 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 "apps/custom_launcher_page_contents.h" |
| 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/render_view_host.h" |
| 10 #include "content/public/browser/site_instance.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/common/renderer_preferences.h" |
| 13 #include "extensions/common/extension_messages.h" |
| 14 |
| 15 namespace apps { |
| 16 |
| 17 CustomLauncherPageContents::CustomLauncherPageContents() { |
| 18 } |
| 19 |
| 20 CustomLauncherPageContents::~CustomLauncherPageContents() { |
| 21 } |
| 22 |
| 23 void CustomLauncherPageContents::Initialize(content::BrowserContext* context, |
| 24 const GURL& url) { |
| 25 url_ = url; |
| 26 |
| 27 extension_function_dispatcher_.reset( |
| 28 new extensions::ExtensionFunctionDispatcher(context, this)); |
| 29 |
| 30 web_contents_.reset( |
| 31 content::WebContents::Create(content::WebContents::CreateParams( |
| 32 context, content::SiteInstance::CreateForURL(context, url_)))); |
| 33 |
| 34 content::WebContentsObserver::Observe(web_contents_.get()); |
| 35 web_contents_->GetMutableRendererPrefs() |
| 36 ->browser_handles_all_top_level_requests = true; |
| 37 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
| 38 } |
| 39 |
| 40 void CustomLauncherPageContents::LoadContents() { |
| 41 web_contents_->GetController().LoadURL( |
| 42 url_, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); |
| 43 } |
| 44 |
| 45 content::WebContents* CustomLauncherPageContents::GetWebContents() const { |
| 46 return web_contents_.get(); |
| 47 } |
| 48 |
| 49 bool CustomLauncherPageContents::OnMessageReceived( |
| 50 const IPC::Message& message) { |
| 51 bool handled = true; |
| 52 IPC_BEGIN_MESSAGE_MAP(CustomLauncherPageContents, message) |
| 53 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| 54 IPC_MESSAGE_UNHANDLED(handled = false) |
| 55 IPC_END_MESSAGE_MAP() |
| 56 return handled; |
| 57 } |
| 58 |
| 59 extensions::WindowController* |
| 60 CustomLauncherPageContents::GetExtensionWindowController() const { |
| 61 return NULL; |
| 62 } |
| 63 |
| 64 content::WebContents* CustomLauncherPageContents::GetAssociatedWebContents() |
| 65 const { |
| 66 return web_contents_.get(); |
| 67 } |
| 68 |
| 69 void CustomLauncherPageContents::OnRequest( |
| 70 const ExtensionHostMsg_Request_Params& params) { |
| 71 extension_function_dispatcher_->Dispatch(params, |
| 72 web_contents_->GetRenderViewHost()); |
| 73 } |
| 74 |
| 75 } // namespace apps |
OLD | NEW |