| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "apps/custom_launcher_page_contents.h" | 5 #include "apps/custom_launcher_page_contents.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "apps/app_delegate.h" |
| 10 #include "apps/app_web_contents_helper.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 12 #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/render_view_host.h" |
| 13 #include "content/public/browser/site_instance.h" | 14 #include "content/public/browser/site_instance.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/common/renderer_preferences.h" | 16 #include "content/public/common/renderer_preferences.h" |
| 16 #include "extensions/common/extension_messages.h" | 17 #include "extensions/common/extension_messages.h" |
| 17 | 18 |
| 18 namespace apps { | 19 namespace apps { |
| 19 | 20 |
| 20 CustomLauncherPageContents::CustomLauncherPageContents() { | 21 CustomLauncherPageContents::CustomLauncherPageContents( |
| 22 scoped_ptr<AppDelegate> app_delegate, |
| 23 const std::string& extension_id) |
| 24 : app_delegate_(app_delegate.Pass()), extension_id_(extension_id) { |
| 21 } | 25 } |
| 22 | 26 |
| 23 CustomLauncherPageContents::~CustomLauncherPageContents() { | 27 CustomLauncherPageContents::~CustomLauncherPageContents() { |
| 24 } | 28 } |
| 25 | 29 |
| 26 void CustomLauncherPageContents::Initialize(content::BrowserContext* context, | 30 void CustomLauncherPageContents::Initialize(content::BrowserContext* context, |
| 27 const GURL& url) { | 31 const GURL& url) { |
| 28 extension_function_dispatcher_.reset( | 32 extension_function_dispatcher_.reset( |
| 29 new extensions::ExtensionFunctionDispatcher(context, this)); | 33 new extensions::ExtensionFunctionDispatcher(context, this)); |
| 30 | 34 |
| 31 web_contents_.reset( | 35 web_contents_.reset( |
| 32 content::WebContents::Create(content::WebContents::CreateParams( | 36 content::WebContents::Create(content::WebContents::CreateParams( |
| 33 context, content::SiteInstance::CreateForURL(context, url)))); | 37 context, content::SiteInstance::CreateForURL(context, url)))); |
| 34 | 38 |
| 35 Observe(web_contents()); | 39 Observe(web_contents()); |
| 36 web_contents_->GetMutableRendererPrefs() | 40 web_contents_->GetMutableRendererPrefs() |
| 37 ->browser_handles_all_top_level_requests = true; | 41 ->browser_handles_all_top_level_requests = true; |
| 38 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); | 42 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
| 39 | 43 |
| 44 helper_.reset(new AppWebContentsHelper( |
| 45 context, extension_id_, web_contents_.get(), app_delegate_.get())); |
| 46 web_contents_->SetDelegate(this); |
| 47 |
| 40 // This observer will activate the extension when it is navigated to, which | 48 // 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 | 49 // allows Dispatcher to give it the proper context and makes it behave like an |
| 42 // extension. | 50 // extension. |
| 43 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 51 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| 44 web_contents()); | 52 web_contents()); |
| 45 | 53 |
| 46 web_contents_->GetController().LoadURL(url, | 54 web_contents_->GetController().LoadURL(url, |
| 47 content::Referrer(), | 55 content::Referrer(), |
| 48 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 56 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 49 std::string()); | 57 std::string()); |
| 50 } | 58 } |
| 51 | 59 |
| 60 content::WebContents* CustomLauncherPageContents::OpenURLFromTab( |
| 61 content::WebContents* source, |
| 62 const content::OpenURLParams& params) { |
| 63 DCHECK_EQ(web_contents_.get(), source); |
| 64 return helper_->OpenURLFromTab(params); |
| 65 } |
| 66 |
| 67 void CustomLauncherPageContents::AddNewContents( |
| 68 content::WebContents* source, |
| 69 content::WebContents* new_contents, |
| 70 WindowOpenDisposition disposition, |
| 71 const gfx::Rect& initial_pos, |
| 72 bool user_gesture, |
| 73 bool* was_blocked) { |
| 74 app_delegate_->AddNewContents(new_contents->GetBrowserContext(), |
| 75 new_contents, |
| 76 disposition, |
| 77 initial_pos, |
| 78 user_gesture, |
| 79 was_blocked); |
| 80 } |
| 81 |
| 82 bool CustomLauncherPageContents::IsPopupOrPanel( |
| 83 const content::WebContents* source) const { |
| 84 return true; |
| 85 } |
| 86 |
| 87 bool CustomLauncherPageContents::ShouldSuppressDialogs() { |
| 88 return true; |
| 89 } |
| 90 |
| 91 bool CustomLauncherPageContents::PreHandleGestureEvent( |
| 92 content::WebContents* source, |
| 93 const blink::WebGestureEvent& event) { |
| 94 return AppWebContentsHelper::ShouldSuppressGestureEvent(event); |
| 95 } |
| 96 |
| 97 content::ColorChooser* CustomLauncherPageContents::OpenColorChooser( |
| 98 content::WebContents* web_contents, |
| 99 SkColor initial_color, |
| 100 const std::vector<content::ColorSuggestion>& suggestionss) { |
| 101 return app_delegate_->ShowColorChooser(web_contents, initial_color); |
| 102 } |
| 103 |
| 104 void CustomLauncherPageContents::RunFileChooser( |
| 105 content::WebContents* tab, |
| 106 const content::FileChooserParams& params) { |
| 107 app_delegate_->RunFileChooser(tab, params); |
| 108 } |
| 109 |
| 110 void CustomLauncherPageContents::RequestToLockMouse( |
| 111 content::WebContents* web_contents, |
| 112 bool user_gesture, |
| 113 bool last_unlocked_by_target) { |
| 114 DCHECK_EQ(web_contents_.get(), web_contents); |
| 115 helper_->RequestToLockMouse(); |
| 116 } |
| 117 |
| 118 void CustomLauncherPageContents::RequestMediaAccessPermission( |
| 119 content::WebContents* web_contents, |
| 120 const content::MediaStreamRequest& request, |
| 121 const content::MediaResponseCallback& callback) { |
| 122 DCHECK_EQ(web_contents_.get(), web_contents); |
| 123 helper_->RequestMediaAccessPermission(request, callback); |
| 124 } |
| 125 |
| 52 bool CustomLauncherPageContents::OnMessageReceived( | 126 bool CustomLauncherPageContents::OnMessageReceived( |
| 53 const IPC::Message& message) { | 127 const IPC::Message& message) { |
| 54 bool handled = true; | 128 bool handled = true; |
| 55 IPC_BEGIN_MESSAGE_MAP(CustomLauncherPageContents, message) | 129 IPC_BEGIN_MESSAGE_MAP(CustomLauncherPageContents, message) |
| 56 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 130 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| 57 IPC_MESSAGE_UNHANDLED(handled = false) | 131 IPC_MESSAGE_UNHANDLED(handled = false) |
| 58 IPC_END_MESSAGE_MAP() | 132 IPC_END_MESSAGE_MAP() |
| 59 return handled; | 133 return handled; |
| 60 } | 134 } |
| 61 | 135 |
| 62 extensions::WindowController* | 136 extensions::WindowController* |
| 63 CustomLauncherPageContents::GetExtensionWindowController() const { | 137 CustomLauncherPageContents::GetExtensionWindowController() const { |
| 64 return NULL; | 138 return NULL; |
| 65 } | 139 } |
| 66 | 140 |
| 67 content::WebContents* CustomLauncherPageContents::GetAssociatedWebContents() | 141 content::WebContents* CustomLauncherPageContents::GetAssociatedWebContents() |
| 68 const { | 142 const { |
| 69 return web_contents(); | 143 return web_contents(); |
| 70 } | 144 } |
| 71 | 145 |
| 72 void CustomLauncherPageContents::OnRequest( | 146 void CustomLauncherPageContents::OnRequest( |
| 73 const ExtensionHostMsg_Request_Params& params) { | 147 const ExtensionHostMsg_Request_Params& params) { |
| 74 extension_function_dispatcher_->Dispatch(params, | 148 extension_function_dispatcher_->Dispatch(params, |
| 75 web_contents_->GetRenderViewHost()); | 149 web_contents_->GetRenderViewHost()); |
| 76 } | 150 } |
| 77 | 151 |
| 78 } // namespace apps | 152 } // namespace apps |
| OLD | NEW |