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

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

Issue 845363004: <webview>, <appview> and <extensionoptions> can run in a detached state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 11 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/metrics/user_metrics.h" 7 #include "base/metrics/user_metrics.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "components/crx_file/id_util.h" 9 #include "components/crx_file/id_util.h"
10 #include "content/public/browser/navigation_details.h" 10 #include "content/public/browser/navigation_details.h"
(...skipping 24 matching lines...) Expand all
35 35
36 // static 36 // static
37 const char ExtensionOptionsGuest::Type[] = "extensionoptions"; 37 const char ExtensionOptionsGuest::Type[] = "extensionoptions";
38 38
39 ExtensionOptionsGuest::ExtensionOptionsGuest( 39 ExtensionOptionsGuest::ExtensionOptionsGuest(
40 content::WebContents* owner_web_contents, 40 content::WebContents* owner_web_contents,
41 int guest_instance_id) 41 int guest_instance_id)
42 : GuestView<ExtensionOptionsGuest>(owner_web_contents, guest_instance_id), 42 : GuestView<ExtensionOptionsGuest>(owner_web_contents, guest_instance_id),
43 extension_options_guest_delegate_( 43 extension_options_guest_delegate_(
44 extensions::ExtensionsAPIClient::Get() 44 extensions::ExtensionsAPIClient::Get()
45 ->CreateExtensionOptionsGuestDelegate(this)), 45 ->CreateExtensionOptionsGuestDelegate(this)) {
46 has_navigated_(false) {
47 } 46 }
48 47
49 ExtensionOptionsGuest::~ExtensionOptionsGuest() { 48 ExtensionOptionsGuest::~ExtensionOptionsGuest() {
50 } 49 }
51 50
52 // static 51 // static
53 extensions::GuestViewBase* ExtensionOptionsGuest::Create( 52 extensions::GuestViewBase* ExtensionOptionsGuest::Create(
54 content::WebContents* owner_web_contents, 53 content::WebContents* owner_web_contents,
55 int guest_instance_id) { 54 int guest_instance_id) {
56 return new ExtensionOptionsGuest(owner_web_contents, guest_instance_id); 55 return new ExtensionOptionsGuest(owner_web_contents, guest_instance_id);
57 } 56 }
58 57
58 bool ExtensionOptionsGuest::CanRunInDetachedState() const {
59 return true;
60 }
61
59 void ExtensionOptionsGuest::CreateWebContents( 62 void ExtensionOptionsGuest::CreateWebContents(
60 const base::DictionaryValue& create_params, 63 const base::DictionaryValue& create_params,
61 const WebContentsCreatedCallback& callback) { 64 const WebContentsCreatedCallback& callback) {
62 // Get the extension's base URL. 65 // Get the extension's base URL.
63 std::string extension_id; 66 std::string extension_id;
64 create_params.GetString(extensionoptions::kExtensionId, &extension_id); 67 create_params.GetString(extensionoptions::kExtensionId, &extension_id);
65 68
66 if (!crx_file::id_util::IdIsValid(extension_id)) { 69 if (!crx_file::id_util::IdIsValid(extension_id)) {
67 callback.Run(nullptr); 70 callback.Run(nullptr);
68 return; 71 return;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Create a WebContents using the extension URL. The options page's 107 // Create a WebContents using the extension URL. The options page's
105 // WebContents should live in the same process as its parent extension's 108 // WebContents should live in the same process as its parent extension's
106 // WebContents, so we can use |extension_url| for creating the SiteInstance. 109 // WebContents, so we can use |extension_url| for creating the SiteInstance.
107 content::SiteInstance* options_site_instance = 110 content::SiteInstance* options_site_instance =
108 content::SiteInstance::CreateForURL(browser_context(), extension_url); 111 content::SiteInstance::CreateForURL(browser_context(), extension_url);
109 WebContents::CreateParams params(browser_context(), options_site_instance); 112 WebContents::CreateParams params(browser_context(), options_site_instance);
110 params.guest_delegate = this; 113 params.guest_delegate = this;
111 callback.Run(WebContents::Create(params)); 114 callback.Run(WebContents::Create(params));
112 } 115 }
113 116
114 void ExtensionOptionsGuest::DidAttachToEmbedder() {
115 // We should not re-navigate on reattachment.
116 if (has_navigated_)
117 return;
118
119 web_contents()->GetController().LoadURL(options_page_,
120 content::Referrer(),
121 ui::PAGE_TRANSITION_LINK,
122 std::string());
123 has_navigated_ = true;
124 }
125
126 void ExtensionOptionsGuest::DidInitialize( 117 void ExtensionOptionsGuest::DidInitialize(
127 const base::DictionaryValue& create_params) { 118 const base::DictionaryValue& create_params) {
128 extension_function_dispatcher_.reset( 119 extension_function_dispatcher_.reset(
129 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); 120 new extensions::ExtensionFunctionDispatcher(browser_context(), this));
130 if (extension_options_guest_delegate_) { 121 if (extension_options_guest_delegate_) {
131 extension_options_guest_delegate_->DidInitialize(); 122 extension_options_guest_delegate_->DidInitialize();
132 } 123 }
124 web_contents()->GetController().LoadURL(options_page_,
125 content::Referrer(),
126 ui::PAGE_TRANSITION_LINK,
127 std::string());
133 } 128 }
134 129
135 void ExtensionOptionsGuest::DidStopLoading() { 130 void ExtensionOptionsGuest::DidStopLoading() {
136 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 131 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
137 DispatchEventToView(new GuestViewBase::Event( 132 DispatchEventToView(new GuestViewBase::Event(
138 extension_options_internal::OnLoad::kEventName, args.Pass())); 133 extension_options_internal::OnLoad::kEventName, args.Pass()));
139 } 134 }
140 135
141 const char* ExtensionOptionsGuest::GetAPINamespace() const { 136 const char* ExtensionOptionsGuest::GetAPINamespace() const {
142 return extensionoptions::kAPINamespace; 137 return extensionoptions::kAPINamespace;
143 } 138 }
144 139
145 int ExtensionOptionsGuest::GetTaskPrefix() const { 140 int ExtensionOptionsGuest::GetTaskPrefix() const {
146 return IDS_EXTENSION_TASK_MANAGER_EXTENSIONOPTIONS_TAG_PREFIX; 141 return IDS_EXTENSION_TASK_MANAGER_EXTENSIONOPTIONS_TAG_PREFIX;
147 } 142 }
148 143
149 void ExtensionOptionsGuest::GuestSizeChangedDueToAutoSize( 144 void ExtensionOptionsGuest::GuestSizeChangedDueToAutoSize(
150 const gfx::Size& old_size, 145 const gfx::Size& old_size,
151 const gfx::Size& new_size) { 146 const gfx::Size& new_size) {
152 extension_options_internal::SizeChangedOptions options; 147 extension_options_internal::SizeChangedOptions options;
153 options.old_width = old_size.width(); 148 options.old_width = old_size.width();
154 options.old_height = old_size.height(); 149 options.old_height = old_size.height();
155 options.new_width = new_size.width(); 150 options.new_width = new_size.width();
156 options.new_height = new_size.height(); 151 options.new_height = new_size.height();
157 DispatchEventToView(new GuestViewBase::Event( 152 DispatchEventToView(new GuestViewBase::Event(
158 extension_options_internal::OnSizeChanged::kEventName, 153 extension_options_internal::OnSizeChanged::kEventName,
159 options.ToValue())); 154 options.ToValue()));
160 } 155 }
161 156
157 bool ExtensionOptionsGuest::IsAutoSizeSupported() const {
158 return true;
159 }
160
161 bool ExtensionOptionsGuest::IsPreferredSizeModeEnabled() const {
162 return true;
163 }
164
162 void ExtensionOptionsGuest::OnPreferredSizeChanged(const gfx::Size& pref_size) { 165 void ExtensionOptionsGuest::OnPreferredSizeChanged(const gfx::Size& pref_size) {
163 extension_options_internal::PreferredSizeChangedOptions options; 166 extension_options_internal::PreferredSizeChangedOptions options;
164 options.width = pref_size.width(); 167 options.width = pref_size.width();
165 options.height = pref_size.height(); 168 options.height = pref_size.height();
166 DispatchEventToView(new GuestViewBase::Event( 169 DispatchEventToView(new GuestViewBase::Event(
167 extension_options_internal::OnPreferredSizeChanged::kEventName, 170 extension_options_internal::OnPreferredSizeChanged::kEventName,
168 options.ToValue())); 171 options.ToValue()));
169 } 172 }
170 173
171 bool ExtensionOptionsGuest::IsAutoSizeSupported() const {
172 return true;
173 }
174
175 bool ExtensionOptionsGuest::IsPreferredSizeModeEnabled() const {
176 return true;
177 }
178
179 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { 174 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const {
180 return web_contents(); 175 return web_contents();
181 } 176 }
182 177
183 content::WebContents* ExtensionOptionsGuest::OpenURLFromTab( 178 content::WebContents* ExtensionOptionsGuest::OpenURLFromTab(
184 content::WebContents* source, 179 content::WebContents* source,
185 const content::OpenURLParams& params) { 180 const content::OpenURLParams& params) {
186 if (!extension_options_guest_delegate_) 181 if (!extension_options_guest_delegate_)
187 return nullptr; 182 return nullptr;
188 183
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return handled; 257 return handled;
263 } 258 }
264 259
265 void ExtensionOptionsGuest::OnRequest( 260 void ExtensionOptionsGuest::OnRequest(
266 const ExtensionHostMsg_Request_Params& params) { 261 const ExtensionHostMsg_Request_Params& params) {
267 extension_function_dispatcher_->Dispatch(params, 262 extension_function_dispatcher_->Dispatch(params,
268 web_contents()->GetRenderViewHost()); 263 web_contents()->GetRenderViewHost());
269 } 264 }
270 265
271 } // namespace extensions 266 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698