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 "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
10 #include "content/public/browser/site_instance.h" | 10 #include "content/public/browser/site_instance.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "extensions/common/extension_messages.h" | 22 #include "extensions/common/extension_messages.h" |
23 #include "extensions/common/feature_switch.h" | 23 #include "extensions/common/feature_switch.h" |
24 #include "extensions/common/manifest_handlers/options_page_info.h" | 24 #include "extensions/common/manifest_handlers/options_page_info.h" |
25 #include "extensions/common/permissions/permissions_data.h" | 25 #include "extensions/common/permissions/permissions_data.h" |
26 #include "extensions/strings/grit/extensions_strings.h" | 26 #include "extensions/strings/grit/extensions_strings.h" |
27 #include "ipc/ipc_message_macros.h" | 27 #include "ipc/ipc_message_macros.h" |
28 | 28 |
29 using content::WebContents; | 29 using content::WebContents; |
30 using namespace extensions::core_api; | 30 using namespace extensions::core_api; |
31 | 31 |
| 32 namespace extensions { |
| 33 |
32 // static | 34 // static |
33 const char ExtensionOptionsGuest::Type[] = "extensionoptions"; | 35 const char ExtensionOptionsGuest::Type[] = "extensionoptions"; |
34 | 36 |
35 ExtensionOptionsGuest::ExtensionOptionsGuest( | 37 ExtensionOptionsGuest::ExtensionOptionsGuest( |
36 content::BrowserContext* browser_context, | 38 content::BrowserContext* browser_context, |
37 int guest_instance_id) | 39 int guest_instance_id) |
38 : GuestView<ExtensionOptionsGuest>(browser_context, guest_instance_id), | 40 : GuestView<ExtensionOptionsGuest>(browser_context, guest_instance_id), |
39 extension_options_guest_delegate_( | 41 extension_options_guest_delegate_( |
40 extensions::ExtensionsAPIClient::Get() | 42 extensions::ExtensionsAPIClient::Get() |
41 ->CreateExtensionOptionsGuestDelegate()) { | 43 ->CreateExtensionOptionsGuestDelegate(this)) { |
42 } | 44 } |
43 | 45 |
44 ExtensionOptionsGuest::~ExtensionOptionsGuest() { | 46 ExtensionOptionsGuest::~ExtensionOptionsGuest() { |
45 } | 47 } |
46 | 48 |
47 // static | 49 // static |
48 extensions::GuestViewBase* ExtensionOptionsGuest::Create( | 50 extensions::GuestViewBase* ExtensionOptionsGuest::Create( |
49 content::BrowserContext* browser_context, | 51 content::BrowserContext* browser_context, |
50 int guest_instance_id) { | 52 int guest_instance_id) { |
51 if (!extensions::FeatureSwitch::embedded_extension_options()->IsEnabled()) { | 53 if (!extensions::FeatureSwitch::embedded_extension_options()->IsEnabled()) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 web_contents()->GetController().LoadURL(options_page_, | 110 web_contents()->GetController().LoadURL(options_page_, |
109 content::Referrer(), | 111 content::Referrer(), |
110 content::PAGE_TRANSITION_LINK, | 112 content::PAGE_TRANSITION_LINK, |
111 std::string()); | 113 std::string()); |
112 } | 114 } |
113 | 115 |
114 void ExtensionOptionsGuest::DidInitialize() { | 116 void ExtensionOptionsGuest::DidInitialize() { |
115 extension_function_dispatcher_.reset( | 117 extension_function_dispatcher_.reset( |
116 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); | 118 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); |
117 if (extension_options_guest_delegate_) { | 119 if (extension_options_guest_delegate_) { |
118 extension_options_guest_delegate_->CreateChromeExtensionWebContentsObserver( | 120 extension_options_guest_delegate_->DidInitialize(); |
119 web_contents()); | |
120 } | 121 } |
121 } | 122 } |
122 | 123 |
123 void ExtensionOptionsGuest::DidStopLoading() { | 124 void ExtensionOptionsGuest::DidStopLoading() { |
124 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 125 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
125 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( | 126 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( |
126 extension_options_internal::OnLoad::kEventName, args.Pass())); | 127 extension_options_internal::OnLoad::kEventName, args.Pass())); |
127 } | 128 } |
128 | 129 |
129 const char* ExtensionOptionsGuest::GetAPINamespace() const { | 130 const char* ExtensionOptionsGuest::GetAPINamespace() const { |
(...skipping 29 matching lines...) Expand all Loading... |
159 const content::OpenURLParams& params) { | 160 const content::OpenURLParams& params) { |
160 if (!extension_options_guest_delegate_) | 161 if (!extension_options_guest_delegate_) |
161 return NULL; | 162 return NULL; |
162 | 163 |
163 // 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 |
164 // this guest view, change the disposition to NEW_FOREGROUND_TAB. | 165 // this guest view, change the disposition to NEW_FOREGROUND_TAB. |
165 if ((!params.url.SchemeIs(extensions::kExtensionScheme) || | 166 if ((!params.url.SchemeIs(extensions::kExtensionScheme) || |
166 params.url.host() != options_page_.host()) && | 167 params.url.host() != options_page_.host()) && |
167 params.disposition == CURRENT_TAB) { | 168 params.disposition == CURRENT_TAB) { |
168 return extension_options_guest_delegate_->OpenURLInNewTab( | 169 return extension_options_guest_delegate_->OpenURLInNewTab( |
169 embedder_web_contents(), | |
170 content::OpenURLParams(params.url, | 170 content::OpenURLParams(params.url, |
171 params.referrer, | 171 params.referrer, |
172 params.frame_tree_node_id, | 172 params.frame_tree_node_id, |
173 NEW_FOREGROUND_TAB, | 173 NEW_FOREGROUND_TAB, |
174 params.transition, | 174 params.transition, |
175 params.is_renderer_initiated)); | 175 params.is_renderer_initiated)); |
176 } | 176 } |
177 return extension_options_guest_delegate_->OpenURLInNewTab( | 177 return extension_options_guest_delegate_->OpenURLInNewTab(params); |
178 embedder_web_contents(), params); | |
179 } | 178 } |
180 | 179 |
181 void ExtensionOptionsGuest::CloseContents(content::WebContents* source) { | 180 void ExtensionOptionsGuest::CloseContents(content::WebContents* source) { |
182 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( | 181 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( |
183 extension_options_internal::OnClose::kEventName, | 182 extension_options_internal::OnClose::kEventName, |
184 make_scoped_ptr(new base::DictionaryValue()))); | 183 make_scoped_ptr(new base::DictionaryValue()))); |
185 } | 184 } |
186 | 185 |
187 bool ExtensionOptionsGuest::HandleContextMenu( | 186 bool ExtensionOptionsGuest::HandleContextMenu( |
188 const content::ContextMenuParams& params) { | 187 const content::ContextMenuParams& params) { |
189 if (!extension_options_guest_delegate_) | 188 if (!extension_options_guest_delegate_) |
190 return false; | 189 return false; |
191 | 190 |
192 return extension_options_guest_delegate_->HandleContextMenu(web_contents(), | 191 return extension_options_guest_delegate_->HandleContextMenu(params); |
193 params); | |
194 } | 192 } |
195 | 193 |
196 bool ExtensionOptionsGuest::ShouldCreateWebContents( | 194 bool ExtensionOptionsGuest::ShouldCreateWebContents( |
197 content::WebContents* web_contents, | 195 content::WebContents* web_contents, |
198 int route_id, | 196 int route_id, |
199 WindowContainerType window_container_type, | 197 WindowContainerType window_container_type, |
200 const base::string16& frame_name, | 198 const base::string16& frame_name, |
201 const GURL& target_url, | 199 const GURL& target_url, |
202 const std::string& partition_id, | 200 const std::string& partition_id, |
203 content::SessionStorageNamespace* session_storage_namespace) { | 201 content::SessionStorageNamespace* session_storage_namespace) { |
204 // This method handles opening links from within the guest. Since this guest | 202 // This method handles opening links from within the guest. Since this guest |
205 // view is used for displaying embedded extension options, we want any | 203 // view is used for displaying embedded extension options, we want any |
206 // external links to be opened in a new tab, not in a new guest view. | 204 // external links to be opened in a new tab, not in a new guest view. |
207 // Therefore we just open the URL in a new tab, and since we aren't handling | 205 // Therefore we just open the URL in a new tab, and since we aren't handling |
208 // the new web contents, we return false. | 206 // the new web contents, we return false. |
209 // TODO(ericzeng): Open the tab in the background if the click was a | 207 // TODO(ericzeng): Open the tab in the background if the click was a |
210 // ctrl-click or middle mouse button click | 208 // ctrl-click or middle mouse button click |
211 if (extension_options_guest_delegate_) { | 209 if (extension_options_guest_delegate_) { |
212 extension_options_guest_delegate_->OpenURLInNewTab( | 210 extension_options_guest_delegate_->OpenURLInNewTab( |
213 embedder_web_contents(), | |
214 content::OpenURLParams(target_url, | 211 content::OpenURLParams(target_url, |
215 content::Referrer(), | 212 content::Referrer(), |
216 NEW_FOREGROUND_TAB, | 213 NEW_FOREGROUND_TAB, |
217 content::PAGE_TRANSITION_LINK, | 214 content::PAGE_TRANSITION_LINK, |
218 false)); | 215 false)); |
219 } | 216 } |
220 return false; | 217 return false; |
221 } | 218 } |
222 | 219 |
223 bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) { | 220 bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) { |
(...skipping 28 matching lines...) Expand all Loading... |
252 attach_params()->GetInteger(extensionoptions::kAttributeMinHeight, | 249 attach_params()->GetInteger(extensionoptions::kAttributeMinHeight, |
253 &min_height); | 250 &min_height); |
254 attach_params()->GetInteger(extensionoptions::kAttributeMinWidth, &min_width); | 251 attach_params()->GetInteger(extensionoptions::kAttributeMinWidth, &min_width); |
255 | 252 |
256 // Call SetAutoSize to apply all the appropriate validation and clipping of | 253 // Call SetAutoSize to apply all the appropriate validation and clipping of |
257 // values. | 254 // values. |
258 SetAutoSize(auto_size_enabled, | 255 SetAutoSize(auto_size_enabled, |
259 gfx::Size(min_width, min_height), | 256 gfx::Size(min_width, min_height), |
260 gfx::Size(max_width, max_height)); | 257 gfx::Size(max_width, max_height)); |
261 } | 258 } |
| 259 |
| 260 } // namespace extensions |
OLD | NEW |