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