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 "extensions/browser/guest_view/extension_options/extension_options_gues
t.h" | 5 #include "extensions/browser/guest_view/extension_options/extension_options_gues
t.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "components/crx_file/id_util.h" | 8 #include "components/crx_file/id_util.h" |
9 #include "components/guest_view/browser/guest_view_event.h" | 9 #include "components/guest_view/browser/guest_view_event.h" |
10 #include "components/guest_view/browser/guest_view_manager.h" | 10 #include "components/guest_view/browser/guest_view_manager.h" |
11 #include "content/public/browser/navigation_details.h" | 11 #include "content/public/browser/navigation_details.h" |
12 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/browser/site_instance.h" | 13 #include "content/public/browser/site_instance.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/common/result_codes.h" | 15 #include "content/public/common/result_codes.h" |
16 #include "extensions/browser/api/extensions_api_client.h" | 16 #include "extensions/browser/api/extensions_api_client.h" |
17 #include "extensions/browser/bad_message.h" | 17 #include "extensions/browser/bad_message.h" |
18 #include "extensions/browser/extension_function_dispatcher.h" | 18 #include "extensions/browser/extension_function_dispatcher.h" |
19 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/browser/extension_web_contents_observer.h" | |
21 #include "extensions/browser/guest_view/extension_options/extension_options_cons
tants.h" | 20 #include "extensions/browser/guest_view/extension_options/extension_options_cons
tants.h" |
22 #include "extensions/browser/guest_view/extension_options/extension_options_gues
t_delegate.h" | 21 #include "extensions/browser/guest_view/extension_options/extension_options_gues
t_delegate.h" |
23 #include "extensions/common/api/extension_options_internal.h" | 22 #include "extensions/common/api/extension_options_internal.h" |
24 #include "extensions/common/constants.h" | 23 #include "extensions/common/constants.h" |
25 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
26 #include "extensions/common/extension_messages.h" | 25 #include "extensions/common/extension_messages.h" |
27 #include "extensions/common/manifest_handlers/options_page_info.h" | 26 #include "extensions/common/manifest_handlers/options_page_info.h" |
28 #include "extensions/common/permissions/permissions_data.h" | 27 #include "extensions/common/permissions/permissions_data.h" |
29 #include "extensions/strings/grit/extensions_strings.h" | 28 #include "extensions/strings/grit/extensions_strings.h" |
30 #include "ipc/ipc_message_macros.h" | 29 #include "ipc/ipc_message_macros.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // WebContents, so we can use |extension_url| for creating the SiteInstance. | 109 // WebContents, so we can use |extension_url| for creating the SiteInstance. |
111 content::SiteInstance* options_site_instance = | 110 content::SiteInstance* options_site_instance = |
112 content::SiteInstance::CreateForURL(browser_context(), extension_url); | 111 content::SiteInstance::CreateForURL(browser_context(), extension_url); |
113 WebContents::CreateParams params(browser_context(), options_site_instance); | 112 WebContents::CreateParams params(browser_context(), options_site_instance); |
114 params.guest_delegate = this; | 113 params.guest_delegate = this; |
115 callback.Run(WebContents::Create(params)); | 114 callback.Run(WebContents::Create(params)); |
116 } | 115 } |
117 | 116 |
118 void ExtensionOptionsGuest::DidInitialize( | 117 void ExtensionOptionsGuest::DidInitialize( |
119 const base::DictionaryValue& create_params) { | 118 const base::DictionaryValue& create_params) { |
120 extension_function_dispatcher_.reset( | 119 ExtensionsAPIClient::Get()->AttachWebContentsHelpers(web_contents()); |
121 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); | |
122 if (extension_options_guest_delegate_) { | |
123 extension_options_guest_delegate_->DidInitialize(); | |
124 } | |
125 web_contents()->GetController().LoadURL(options_page_, | 120 web_contents()->GetController().LoadURL(options_page_, |
126 content::Referrer(), | 121 content::Referrer(), |
127 ui::PAGE_TRANSITION_LINK, | 122 ui::PAGE_TRANSITION_LINK, |
128 std::string()); | 123 std::string()); |
129 } | 124 } |
130 | 125 |
131 void ExtensionOptionsGuest::GuestViewDidStopLoading() { | 126 void ExtensionOptionsGuest::GuestViewDidStopLoading() { |
132 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 127 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
133 DispatchEventToView(new GuestViewEvent( | 128 DispatchEventToView(new GuestViewEvent( |
134 extension_options_internal::OnLoad::kEventName, args.Pass())); | 129 extension_options_internal::OnLoad::kEventName, args.Pass())); |
(...skipping 18 matching lines...) Expand all Loading... |
153 void ExtensionOptionsGuest::OnPreferredSizeChanged(const gfx::Size& pref_size) { | 148 void ExtensionOptionsGuest::OnPreferredSizeChanged(const gfx::Size& pref_size) { |
154 extension_options_internal::PreferredSizeChangedOptions options; | 149 extension_options_internal::PreferredSizeChangedOptions options; |
155 // Convert the size from physical pixels to logical pixels. | 150 // Convert the size from physical pixels to logical pixels. |
156 options.width = PhysicalPixelsToLogicalPixels(pref_size.width()); | 151 options.width = PhysicalPixelsToLogicalPixels(pref_size.width()); |
157 options.height = PhysicalPixelsToLogicalPixels(pref_size.height()); | 152 options.height = PhysicalPixelsToLogicalPixels(pref_size.height()); |
158 DispatchEventToView(new GuestViewEvent( | 153 DispatchEventToView(new GuestViewEvent( |
159 extension_options_internal::OnPreferredSizeChanged::kEventName, | 154 extension_options_internal::OnPreferredSizeChanged::kEventName, |
160 options.ToValue())); | 155 options.ToValue())); |
161 } | 156 } |
162 | 157 |
163 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { | |
164 return web_contents(); | |
165 } | |
166 | |
167 content::WebContents* ExtensionOptionsGuest::OpenURLFromTab( | 158 content::WebContents* ExtensionOptionsGuest::OpenURLFromTab( |
168 content::WebContents* source, | 159 content::WebContents* source, |
169 const content::OpenURLParams& params) { | 160 const content::OpenURLParams& params) { |
170 if (!extension_options_guest_delegate_) | 161 if (!extension_options_guest_delegate_) |
171 return nullptr; | 162 return nullptr; |
172 | 163 |
173 // Don't allow external URLs with the CURRENT_TAB disposition be opened in | 164 // Don't allow external URLs with the CURRENT_TAB disposition be opened in |
174 // this guest view, change the disposition to NEW_FOREGROUND_TAB. | 165 // this guest view, change the disposition to NEW_FOREGROUND_TAB. |
175 if ((!params.url.SchemeIs(extensions::kExtensionScheme) || | 166 if ((!params.url.SchemeIs(extensions::kExtensionScheme) || |
176 params.url.host() != options_page_.host()) && | 167 params.url.host() != options_page_.host()) && |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 ui_zoom::ZoomController::ZOOM_MODE_ISOLATED); | 228 ui_zoom::ZoomController::ZOOM_MODE_ISOLATED); |
238 SetGuestZoomLevelToMatchEmbedder(); | 229 SetGuestZoomLevelToMatchEmbedder(); |
239 | 230 |
240 if (params.url.GetOrigin() != options_page_.GetOrigin()) { | 231 if (params.url.GetOrigin() != options_page_.GetOrigin()) { |
241 bad_message::ReceivedBadMessage(web_contents()->GetRenderProcessHost(), | 232 bad_message::ReceivedBadMessage(web_contents()->GetRenderProcessHost(), |
242 bad_message::EOG_BAD_ORIGIN); | 233 bad_message::EOG_BAD_ORIGIN); |
243 } | 234 } |
244 } | 235 } |
245 } | 236 } |
246 | 237 |
247 bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) { | |
248 bool handled = true; | |
249 IPC_BEGIN_MESSAGE_MAP(ExtensionOptionsGuest, message) | |
250 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
251 IPC_MESSAGE_UNHANDLED(handled = false) | |
252 IPC_END_MESSAGE_MAP() | |
253 return handled; | |
254 } | |
255 | |
256 void ExtensionOptionsGuest::OnRequest( | |
257 const ExtensionHostMsg_Request_Params& params) { | |
258 extension_function_dispatcher_->Dispatch(params, | |
259 web_contents()->GetRenderViewHost()); | |
260 } | |
261 | |
262 } // namespace extensions | 238 } // namespace extensions |
OLD | NEW |