Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Side by Side Diff: extensions/browser/guest_view/extension_options/extension_options_guest.cc

Issue 562353002: Refactor ExtensionOptionsGuestDelegate to have an ExtensionOptionsGuest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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_
119 web_contents()); 121 ->CreateChromeExtensionWebContentsObserver();
Fady Samuel 2014/09/11 18:53:36 I would just call it DidInitialize, otherwise you'
120 } 122 }
121 } 123 }
122 124
123 void ExtensionOptionsGuest::DidStopLoading() { 125 void ExtensionOptionsGuest::DidStopLoading() {
124 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 126 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
125 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( 127 DispatchEventToEmbedder(new extensions::GuestViewBase::Event(
126 extension_options_internal::OnLoad::kEventName, args.Pass())); 128 extension_options_internal::OnLoad::kEventName, args.Pass()));
127 } 129 }
128 130
129 const char* ExtensionOptionsGuest::GetAPINamespace() const { 131 const char* ExtensionOptionsGuest::GetAPINamespace() const {
(...skipping 29 matching lines...) Expand all
159 const content::OpenURLParams& params) { 161 const content::OpenURLParams& params) {
160 if (!extension_options_guest_delegate_) 162 if (!extension_options_guest_delegate_)
161 return NULL; 163 return NULL;
162 164
163 // Don't allow external URLs with the CURRENT_TAB disposition be opened in 165 // Don't allow external URLs with the CURRENT_TAB disposition be opened in
164 // this guest view, change the disposition to NEW_FOREGROUND_TAB. 166 // this guest view, change the disposition to NEW_FOREGROUND_TAB.
165 if ((!params.url.SchemeIs(extensions::kExtensionScheme) || 167 if ((!params.url.SchemeIs(extensions::kExtensionScheme) ||
166 params.url.host() != options_page_.host()) && 168 params.url.host() != options_page_.host()) &&
167 params.disposition == CURRENT_TAB) { 169 params.disposition == CURRENT_TAB) {
168 return extension_options_guest_delegate_->OpenURLInNewTab( 170 return extension_options_guest_delegate_->OpenURLInNewTab(
169 embedder_web_contents(),
170 content::OpenURLParams(params.url, 171 content::OpenURLParams(params.url,
171 params.referrer, 172 params.referrer,
172 params.frame_tree_node_id, 173 params.frame_tree_node_id,
173 NEW_FOREGROUND_TAB, 174 NEW_FOREGROUND_TAB,
174 params.transition, 175 params.transition,
175 params.is_renderer_initiated)); 176 params.is_renderer_initiated));
176 } 177 }
177 return extension_options_guest_delegate_->OpenURLInNewTab( 178 return extension_options_guest_delegate_->OpenURLInNewTab(params);
178 embedder_web_contents(), params);
179 } 179 }
180 180
181 void ExtensionOptionsGuest::CloseContents(content::WebContents* source) { 181 void ExtensionOptionsGuest::CloseContents(content::WebContents* source) {
182 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( 182 DispatchEventToEmbedder(new extensions::GuestViewBase::Event(
183 extension_options_internal::OnClose::kEventName, 183 extension_options_internal::OnClose::kEventName,
184 make_scoped_ptr(new base::DictionaryValue()))); 184 make_scoped_ptr(new base::DictionaryValue())));
185 } 185 }
186 186
187 bool ExtensionOptionsGuest::HandleContextMenu( 187 bool ExtensionOptionsGuest::HandleContextMenu(
188 const content::ContextMenuParams& params) { 188 const content::ContextMenuParams& params) {
189 if (!extension_options_guest_delegate_) 189 if (!extension_options_guest_delegate_)
190 return false; 190 return false;
191 191
192 return extension_options_guest_delegate_->HandleContextMenu(web_contents(), 192 return extension_options_guest_delegate_->HandleContextMenu(params);
193 params);
194 } 193 }
195 194
196 bool ExtensionOptionsGuest::ShouldCreateWebContents( 195 bool ExtensionOptionsGuest::ShouldCreateWebContents(
197 content::WebContents* web_contents, 196 content::WebContents* web_contents,
198 int route_id, 197 int route_id,
199 WindowContainerType window_container_type, 198 WindowContainerType window_container_type,
200 const base::string16& frame_name, 199 const base::string16& frame_name,
201 const GURL& target_url, 200 const GURL& target_url,
202 const std::string& partition_id, 201 const std::string& partition_id,
203 content::SessionStorageNamespace* session_storage_namespace) { 202 content::SessionStorageNamespace* session_storage_namespace) {
204 // This method handles opening links from within the guest. Since this guest 203 // This method handles opening links from within the guest. Since this guest
205 // view is used for displaying embedded extension options, we want any 204 // 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. 205 // 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 206 // Therefore we just open the URL in a new tab, and since we aren't handling
208 // the new web contents, we return false. 207 // the new web contents, we return false.
209 // TODO(ericzeng): Open the tab in the background if the click was a 208 // TODO(ericzeng): Open the tab in the background if the click was a
210 // ctrl-click or middle mouse button click 209 // ctrl-click or middle mouse button click
211 if (extension_options_guest_delegate_) { 210 if (extension_options_guest_delegate_) {
212 extension_options_guest_delegate_->OpenURLInNewTab( 211 extension_options_guest_delegate_->OpenURLInNewTab(
213 embedder_web_contents(),
214 content::OpenURLParams(target_url, 212 content::OpenURLParams(target_url,
215 content::Referrer(), 213 content::Referrer(),
216 NEW_FOREGROUND_TAB, 214 NEW_FOREGROUND_TAB,
217 content::PAGE_TRANSITION_LINK, 215 content::PAGE_TRANSITION_LINK,
218 false)); 216 false));
219 } 217 }
220 return false; 218 return false;
221 } 219 }
222 220
223 bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) { 221 bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) {
(...skipping 28 matching lines...) Expand all
252 attach_params()->GetInteger(extensionoptions::kAttributeMinHeight, 250 attach_params()->GetInteger(extensionoptions::kAttributeMinHeight,
253 &min_height); 251 &min_height);
254 attach_params()->GetInteger(extensionoptions::kAttributeMinWidth, &min_width); 252 attach_params()->GetInteger(extensionoptions::kAttributeMinWidth, &min_width);
255 253
256 // Call SetAutoSize to apply all the appropriate validation and clipping of 254 // Call SetAutoSize to apply all the appropriate validation and clipping of
257 // values. 255 // values.
258 SetAutoSize(auto_size_enabled, 256 SetAutoSize(auto_size_enabled,
259 gfx::Size(min_width, min_height), 257 gfx::Size(min_width, min_height),
260 gfx::Size(max_width, max_height)); 258 gfx::Size(max_width, max_height));
261 } 259 }
260
261 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698