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