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/web_view/web_view_guest.h" | 5 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" | 10 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 163 } |
164 *persist_storage = true; | 164 *persist_storage = true; |
165 } else { | 165 } else { |
166 *storage_partition_id = partition_str; | 166 *storage_partition_id = partition_str; |
167 *persist_storage = false; | 167 *persist_storage = false; |
168 } | 168 } |
169 } | 169 } |
170 | 170 |
171 void RemoveWebViewEventListenersOnIOThread( | 171 void RemoveWebViewEventListenersOnIOThread( |
172 void* profile, | 172 void* profile, |
173 const std::string& extension_id, | |
174 int embedder_process_id, | 173 int embedder_process_id, |
175 int view_instance_id) { | 174 int view_instance_id) { |
176 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 175 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
177 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( | 176 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( |
178 profile, | 177 profile, |
179 extension_id, | |
180 embedder_process_id, | 178 embedder_process_id, |
181 view_instance_id); | 179 view_instance_id); |
182 } | 180 } |
183 | 181 |
184 double ConvertZoomLevelToZoomFactor(double zoom_level) { | 182 double ConvertZoomLevelToZoomFactor(double zoom_level) { |
185 double zoom_factor = content::ZoomLevelToZoomFactor(zoom_level); | 183 double zoom_factor = content::ZoomLevelToZoomFactor(zoom_level); |
186 // Because the conversion from zoom level to zoom factor isn't perfect, the | 184 // Because the conversion from zoom level to zoom factor isn't perfect, the |
187 // resulting zoom factor is rounded to the nearest 6th decimal place. | 185 // resulting zoom factor is rounded to the nearest 6th decimal place. |
188 zoom_factor = round(zoom_factor * 1000000) / 1000000; | 186 zoom_factor = round(zoom_factor * 1000000) / 1000000; |
189 return zoom_factor; | 187 return zoom_factor; |
190 } | 188 } |
191 | 189 |
| 190 using WebViewKey = std::pair<int, int>; |
| 191 using WebViewKeyToIDMap = std::map<WebViewKey, int>; |
| 192 static base::LazyInstance<WebViewKeyToIDMap> web_view_key_to_id_map = |
| 193 LAZY_INSTANCE_INITIALIZER; |
| 194 |
192 } // namespace | 195 } // namespace |
193 | 196 |
194 // static | 197 // static |
| 198 void WebViewGuest::CleanUp(int embedder_process_id, int view_instance_id) { |
| 199 GuestViewBase::CleanUp(embedder_process_id, view_instance_id); |
| 200 |
| 201 auto rph = content::RenderProcessHost::FromID(embedder_process_id); |
| 202 auto browser_context = rph->GetBrowserContext(); |
| 203 |
| 204 // Clean up rules registries for the WebView. |
| 205 WebViewKey key(embedder_process_id, view_instance_id); |
| 206 auto it = web_view_key_to_id_map.Get().find(key); |
| 207 if (it != web_view_key_to_id_map.Get().end()) { |
| 208 auto rules_registry_id = it->second; |
| 209 web_view_key_to_id_map.Get().erase(it); |
| 210 RulesRegistryService::Get(browser_context) |
| 211 ->RemoveRulesRegistriesByID(rules_registry_id); |
| 212 } |
| 213 |
| 214 // Clean up web request event listeners for the WebView. |
| 215 content::BrowserThread::PostTask( |
| 216 content::BrowserThread::IO, |
| 217 FROM_HERE, |
| 218 base::Bind( |
| 219 &RemoveWebViewEventListenersOnIOThread, |
| 220 browser_context, |
| 221 embedder_process_id, |
| 222 view_instance_id)); |
| 223 } |
| 224 |
| 225 // static |
195 GuestViewBase* WebViewGuest::Create(content::WebContents* owner_web_contents) { | 226 GuestViewBase* WebViewGuest::Create(content::WebContents* owner_web_contents) { |
196 return new WebViewGuest(owner_web_contents); | 227 return new WebViewGuest(owner_web_contents); |
197 } | 228 } |
198 | 229 |
199 // static | 230 // static |
200 bool WebViewGuest::GetGuestPartitionConfigForSite( | 231 bool WebViewGuest::GetGuestPartitionConfigForSite( |
201 const GURL& site, | 232 const GURL& site, |
202 std::string* partition_domain, | 233 std::string* partition_domain, |
203 std::string* partition_name, | 234 std::string* partition_name, |
204 bool* in_memory) { | 235 bool* in_memory) { |
(...skipping 10 matching lines...) Expand all Loading... |
215 // The partition name is user supplied value, which we have encoded when the | 246 // The partition name is user supplied value, which we have encoded when the |
216 // URL was created, so it needs to be decoded. | 247 // URL was created, so it needs to be decoded. |
217 *partition_name = | 248 *partition_name = |
218 net::UnescapeURLComponent(site.query(), net::UnescapeRule::NORMAL); | 249 net::UnescapeURLComponent(site.query(), net::UnescapeRule::NORMAL); |
219 return true; | 250 return true; |
220 } | 251 } |
221 | 252 |
222 // static | 253 // static |
223 const char WebViewGuest::Type[] = "webview"; | 254 const char WebViewGuest::Type[] = "webview"; |
224 | 255 |
225 using WebViewKey = std::pair<int, int>; | |
226 using WebViewKeyToIDMap = std::map<WebViewKey, int>; | |
227 static base::LazyInstance<WebViewKeyToIDMap> web_view_key_to_id_map = | |
228 LAZY_INSTANCE_INITIALIZER; | |
229 | |
230 // static | 256 // static |
231 int WebViewGuest::GetOrGenerateRulesRegistryID( | 257 int WebViewGuest::GetOrGenerateRulesRegistryID( |
232 int embedder_process_id, | 258 int embedder_process_id, |
233 int webview_instance_id) { | 259 int webview_instance_id) { |
234 bool is_web_view = embedder_process_id && webview_instance_id; | 260 bool is_web_view = embedder_process_id && webview_instance_id; |
235 if (!is_web_view) | 261 if (!is_web_view) |
236 return RulesRegistryService::kDefaultRulesRegistryID; | 262 return RulesRegistryService::kDefaultRulesRegistryID; |
237 | 263 |
238 WebViewKey key = std::make_pair(embedder_process_id, webview_instance_id); | 264 WebViewKey key = std::make_pair(embedder_process_id, webview_instance_id); |
239 auto it = web_view_key_to_id_map.Get().find(key); | 265 auto it = web_view_key_to_id_map.Get().find(key); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 } | 407 } |
382 | 408 |
383 void WebViewGuest::EmbedderFullscreenToggled(bool entered_fullscreen) { | 409 void WebViewGuest::EmbedderFullscreenToggled(bool entered_fullscreen) { |
384 is_embedder_fullscreen_ = entered_fullscreen; | 410 is_embedder_fullscreen_ = entered_fullscreen; |
385 // If the embedder has got out of fullscreen, we get out of fullscreen | 411 // If the embedder has got out of fullscreen, we get out of fullscreen |
386 // mode as well. | 412 // mode as well. |
387 if (!entered_fullscreen) | 413 if (!entered_fullscreen) |
388 SetFullscreenState(false); | 414 SetFullscreenState(false); |
389 } | 415 } |
390 | 416 |
391 void WebViewGuest::EmbedderWillBeDestroyed() { | |
392 // Clean up rules registries for the webview. | |
393 RulesRegistryService::Get(browser_context()) | |
394 ->RemoveRulesRegistriesByID(rules_registry_id_); | |
395 WebViewKey key(owner_web_contents()->GetRenderProcessHost()->GetID(), | |
396 view_instance_id()); | |
397 web_view_key_to_id_map.Get().erase(key); | |
398 | |
399 content::BrowserThread::PostTask( | |
400 content::BrowserThread::IO, | |
401 FROM_HERE, | |
402 base::Bind( | |
403 &RemoveWebViewEventListenersOnIOThread, | |
404 browser_context(), | |
405 owner_host(), | |
406 owner_web_contents()->GetRenderProcessHost()->GetID(), | |
407 view_instance_id())); | |
408 } | |
409 | |
410 const char* WebViewGuest::GetAPINamespace() const { | 417 const char* WebViewGuest::GetAPINamespace() const { |
411 return webview::kAPINamespace; | 418 return webview::kAPINamespace; |
412 } | 419 } |
413 | 420 |
414 int WebViewGuest::GetTaskPrefix() const { | 421 int WebViewGuest::GetTaskPrefix() const { |
415 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; | 422 return IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX; |
416 } | 423 } |
417 | 424 |
418 void WebViewGuest::GuestDestroyed() { | 425 void WebViewGuest::GuestDestroyed() { |
419 // Clean up custom context menu items for this guest. | 426 // Clean up custom context menu items for this guest. |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1446 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1440 DispatchEventToView( | 1447 DispatchEventToView( |
1441 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); | 1448 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); |
1442 } | 1449 } |
1443 // Since we changed fullscreen state, sending a Resize message ensures that | 1450 // Since we changed fullscreen state, sending a Resize message ensures that |
1444 // renderer/ sees the change. | 1451 // renderer/ sees the change. |
1445 web_contents()->GetRenderViewHost()->WasResized(); | 1452 web_contents()->GetRenderViewHost()->WasResized(); |
1446 } | 1453 } |
1447 | 1454 |
1448 } // namespace extensions | 1455 } // namespace extensions |
OLD | NEW |