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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 content::BrowserThread::PostTask( | 232 content::BrowserThread::PostTask( |
233 content::BrowserThread::IO, | 233 content::BrowserThread::IO, |
234 FROM_HERE, | 234 FROM_HERE, |
235 base::Bind( | 235 base::Bind( |
236 &RemoveWebViewEventListenersOnIOThread, | 236 &RemoveWebViewEventListenersOnIOThread, |
237 browser_context, | 237 browser_context, |
238 embedder_process_id, | 238 embedder_process_id, |
239 view_instance_id)); | 239 view_instance_id)); |
240 | 240 |
241 // Clean up content scripts for the WebView. | 241 // Clean up content scripts for the WebView. |
242 auto csm = WebViewContentScriptManager::Get(browser_context); | 242 auto* csm = WebViewContentScriptManager::Get(browser_context); |
243 csm->RemoveAllContentScriptsForWebView(embedder_process_id, view_instance_id); | 243 csm->RemoveAllContentScriptsForWebView(embedder_process_id, view_instance_id); |
244 | 244 |
245 // Allow an extensions browser client to potentially perform more cleanup. | 245 // Allow an extensions browser client to potentially perform more cleanup. |
246 ExtensionsBrowserClient::Get()->CleanUpWebView( | 246 ExtensionsBrowserClient::Get()->CleanUpWebView( |
247 browser_context, embedder_process_id, view_instance_id); | 247 browser_context, embedder_process_id, view_instance_id); |
248 } | 248 } |
249 | 249 |
250 // static | 250 // static |
251 GuestViewBase* WebViewGuest::Create(WebContents* owner_web_contents) { | 251 GuestViewBase* WebViewGuest::Create(WebContents* owner_web_contents) { |
252 return new WebViewGuest(owner_web_contents); | 252 return new WebViewGuest(owner_web_contents); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 int webview_instance_id) { | 296 int webview_instance_id) { |
297 bool is_web_view = embedder_process_id && webview_instance_id; | 297 bool is_web_view = embedder_process_id && webview_instance_id; |
298 if (!is_web_view) | 298 if (!is_web_view) |
299 return RulesRegistryService::kDefaultRulesRegistryID; | 299 return RulesRegistryService::kDefaultRulesRegistryID; |
300 | 300 |
301 WebViewKey key = std::make_pair(embedder_process_id, webview_instance_id); | 301 WebViewKey key = std::make_pair(embedder_process_id, webview_instance_id); |
302 auto it = web_view_key_to_id_map.Get().find(key); | 302 auto it = web_view_key_to_id_map.Get().find(key); |
303 if (it != web_view_key_to_id_map.Get().end()) | 303 if (it != web_view_key_to_id_map.Get().end()) |
304 return it->second; | 304 return it->second; |
305 | 305 |
306 auto rph = RenderProcessHost::FromID(embedder_process_id); | 306 auto* rph = RenderProcessHost::FromID(embedder_process_id); |
307 int rules_registry_id = | 307 int rules_registry_id = |
308 RulesRegistryService::Get(rph->GetBrowserContext())-> | 308 RulesRegistryService::Get(rph->GetBrowserContext())-> |
309 GetNextRulesRegistryID(); | 309 GetNextRulesRegistryID(); |
310 web_view_key_to_id_map.Get()[key] = rules_registry_id; | 310 web_view_key_to_id_map.Get()[key] = rules_registry_id; |
311 return rules_registry_id; | 311 return rules_registry_id; |
312 } | 312 } |
313 | 313 |
314 bool WebViewGuest::CanRunInDetachedState() const { | 314 bool WebViewGuest::CanRunInDetachedState() const { |
315 return true; | 315 return true; |
316 } | 316 } |
(...skipping 23 matching lines...) Expand all Loading... |
340 std::string partition_domain = GetOwnerSiteURL().host(); | 340 std::string partition_domain = GetOwnerSiteURL().host(); |
341 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", | 341 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", |
342 content::kGuestScheme, | 342 content::kGuestScheme, |
343 partition_domain.c_str(), | 343 partition_domain.c_str(), |
344 persist_storage ? "persist" : "", | 344 persist_storage ? "persist" : "", |
345 url_encoded_partition.c_str())); | 345 url_encoded_partition.c_str())); |
346 | 346 |
347 // If we already have a webview tag in the same app using the same storage | 347 // If we already have a webview tag in the same app using the same storage |
348 // partition, we should use the same SiteInstance so the existing tag and | 348 // partition, we should use the same SiteInstance so the existing tag and |
349 // the new tag can script each other. | 349 // the new tag can script each other. |
350 auto guest_view_manager = GuestViewManager::FromBrowserContext( | 350 auto* guest_view_manager = GuestViewManager::FromBrowserContext( |
351 owner_render_process_host->GetBrowserContext()); | 351 owner_render_process_host->GetBrowserContext()); |
352 scoped_refptr<content::SiteInstance> guest_site_instance = | 352 scoped_refptr<content::SiteInstance> guest_site_instance = |
353 guest_view_manager->GetGuestSiteInstance(guest_site); | 353 guest_view_manager->GetGuestSiteInstance(guest_site); |
354 if (!guest_site_instance) { | 354 if (!guest_site_instance) { |
355 // Create the SiteInstance in a new BrowsingInstance, which will ensure | 355 // Create the SiteInstance in a new BrowsingInstance, which will ensure |
356 // that webview tags are also not allowed to send messages across | 356 // that webview tags are also not allowed to send messages across |
357 // different partitions. | 357 // different partitions. |
358 guest_site_instance = content::SiteInstance::CreateForURL( | 358 guest_site_instance = content::SiteInstance::CreateForURL( |
359 owner_render_process_host->GetBrowserContext(), guest_site); | 359 owner_render_process_host->GetBrowserContext(), guest_site); |
360 } | 360 } |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 bool user_gesture, | 980 bool user_gesture, |
981 bool last_unlocked_by_target, | 981 bool last_unlocked_by_target, |
982 const base::Callback<void(bool)>& callback) { | 982 const base::Callback<void(bool)>& callback) { |
983 web_view_permission_helper_->RequestPointerLockPermission( | 983 web_view_permission_helper_->RequestPointerLockPermission( |
984 user_gesture, | 984 user_gesture, |
985 last_unlocked_by_target, | 985 last_unlocked_by_target, |
986 callback); | 986 callback); |
987 } | 987 } |
988 | 988 |
989 void WebViewGuest::SignalWhenReady(const base::Closure& callback) { | 989 void WebViewGuest::SignalWhenReady(const base::Closure& callback) { |
990 auto manager = WebViewContentScriptManager::Get(browser_context()); | 990 auto* manager = WebViewContentScriptManager::Get(browser_context()); |
991 manager->SignalOnScriptsLoaded(callback); | 991 manager->SignalOnScriptsLoaded(callback); |
992 } | 992 } |
993 | 993 |
994 bool WebViewGuest::ShouldHandleFindRequestsForEmbedder() const { | 994 bool WebViewGuest::ShouldHandleFindRequestsForEmbedder() const { |
995 if (web_view_guest_delegate_) | 995 if (web_view_guest_delegate_) |
996 return web_view_guest_delegate_->ShouldHandleFindRequestsForEmbedder(); | 996 return web_view_guest_delegate_->ShouldHandleFindRequestsForEmbedder(); |
997 return false; | 997 return false; |
998 } | 998 } |
999 | 999 |
1000 void WebViewGuest::WillAttachToEmbedder() { | 1000 void WebViewGuest::WillAttachToEmbedder() { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 | 1146 |
1147 void WebViewGuest::SetName(const std::string& name) { | 1147 void WebViewGuest::SetName(const std::string& name) { |
1148 if (name_ == name) | 1148 if (name_ == name) |
1149 return; | 1149 return; |
1150 name_ = name; | 1150 name_ = name; |
1151 | 1151 |
1152 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); | 1152 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); |
1153 } | 1153 } |
1154 | 1154 |
1155 void WebViewGuest::SetZoom(double zoom_factor) { | 1155 void WebViewGuest::SetZoom(double zoom_factor) { |
1156 auto zoom_controller = ZoomController::FromWebContents(web_contents()); | 1156 auto* zoom_controller = ZoomController::FromWebContents(web_contents()); |
1157 DCHECK(zoom_controller); | 1157 DCHECK(zoom_controller); |
1158 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); | 1158 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); |
1159 zoom_controller->SetZoomLevel(zoom_level); | 1159 zoom_controller->SetZoomLevel(zoom_level); |
1160 } | 1160 } |
1161 | 1161 |
1162 void WebViewGuest::SetZoomMode(ZoomController::ZoomMode zoom_mode) { | 1162 void WebViewGuest::SetZoomMode(ZoomController::ZoomMode zoom_mode) { |
1163 ZoomController::FromWebContents(web_contents())->SetZoomMode(zoom_mode); | 1163 ZoomController::FromWebContents(web_contents())->SetZoomMode(zoom_mode); |
1164 } | 1164 } |
1165 | 1165 |
1166 void WebViewGuest::SetAllowTransparency(bool allow) { | 1166 void WebViewGuest::SetAllowTransparency(bool allow) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 // This code path is also taken on client-side redirects from about:blank. | 1310 // This code path is also taken on client-side redirects from about:blank. |
1311 CreateNewGuestWebViewWindow(params); | 1311 CreateNewGuestWebViewWindow(params); |
1312 return nullptr; | 1312 return nullptr; |
1313 } | 1313 } |
1314 | 1314 |
1315 void WebViewGuest::WebContentsCreated(WebContents* source_contents, | 1315 void WebViewGuest::WebContentsCreated(WebContents* source_contents, |
1316 int opener_render_frame_id, | 1316 int opener_render_frame_id, |
1317 const std::string& frame_name, | 1317 const std::string& frame_name, |
1318 const GURL& target_url, | 1318 const GURL& target_url, |
1319 WebContents* new_contents) { | 1319 WebContents* new_contents) { |
1320 auto guest = WebViewGuest::FromWebContents(new_contents); | 1320 auto* guest = WebViewGuest::FromWebContents(new_contents); |
1321 CHECK(guest); | 1321 CHECK(guest); |
1322 guest->SetOpener(this); | 1322 guest->SetOpener(this); |
1323 guest->name_ = frame_name; | 1323 guest->name_ = frame_name; |
1324 pending_new_windows_.insert( | 1324 pending_new_windows_.insert( |
1325 std::make_pair(guest, NewWindowInfo(target_url, frame_name))); | 1325 std::make_pair(guest, NewWindowInfo(target_url, frame_name))); |
1326 } | 1326 } |
1327 | 1327 |
1328 void WebViewGuest::EnterFullscreenModeForTab(WebContents* web_contents, | 1328 void WebViewGuest::EnterFullscreenModeForTab(WebContents* web_contents, |
1329 const GURL& origin) { | 1329 const GURL& origin) { |
1330 // Ask the embedder for permission. | 1330 // Ask the embedder for permission. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 } | 1402 } |
1403 GuestViewBase::LoadURLWithParams(load_url_params); | 1403 GuestViewBase::LoadURLWithParams(load_url_params); |
1404 | 1404 |
1405 src_ = validated_url; | 1405 src_ = validated_url; |
1406 } | 1406 } |
1407 | 1407 |
1408 void WebViewGuest::RequestNewWindowPermission(WindowOpenDisposition disposition, | 1408 void WebViewGuest::RequestNewWindowPermission(WindowOpenDisposition disposition, |
1409 const gfx::Rect& initial_bounds, | 1409 const gfx::Rect& initial_bounds, |
1410 bool user_gesture, | 1410 bool user_gesture, |
1411 WebContents* new_contents) { | 1411 WebContents* new_contents) { |
1412 auto guest = WebViewGuest::FromWebContents(new_contents); | 1412 auto* guest = WebViewGuest::FromWebContents(new_contents); |
1413 if (!guest) | 1413 if (!guest) |
1414 return; | 1414 return; |
1415 auto it = pending_new_windows_.find(guest); | 1415 auto it = pending_new_windows_.find(guest); |
1416 if (it == pending_new_windows_.end()) | 1416 if (it == pending_new_windows_.end()) |
1417 return; | 1417 return; |
1418 const NewWindowInfo& new_window_info = it->second; | 1418 const NewWindowInfo& new_window_info = it->second; |
1419 | 1419 |
1420 // Retrieve the opener partition info if we have it. | 1420 // Retrieve the opener partition info if we have it. |
1421 const GURL& site_url = new_contents->GetSiteInstance()->GetSiteURL(); | 1421 const GURL& site_url = new_contents->GetSiteInstance()->GetSiteURL(); |
1422 std::string storage_partition_id = GetStoragePartitionIdFromSiteURL(site_url); | 1422 std::string storage_partition_id = GetStoragePartitionIdFromSiteURL(site_url); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 GURL default_url(base::StringPrintf("%s://%s/", | 1454 GURL default_url(base::StringPrintf("%s://%s/", |
1455 kExtensionScheme, | 1455 kExtensionScheme, |
1456 owner_host().c_str())); | 1456 owner_host().c_str())); |
1457 return default_url.Resolve(src); | 1457 return default_url.Resolve(src); |
1458 } | 1458 } |
1459 | 1459 |
1460 void WebViewGuest::OnWebViewNewWindowResponse( | 1460 void WebViewGuest::OnWebViewNewWindowResponse( |
1461 int new_window_instance_id, | 1461 int new_window_instance_id, |
1462 bool allow, | 1462 bool allow, |
1463 const std::string& user_input) { | 1463 const std::string& user_input) { |
1464 auto guest = | 1464 auto* guest = |
1465 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), | 1465 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), |
1466 new_window_instance_id); | 1466 new_window_instance_id); |
1467 if (!guest) | 1467 if (!guest) |
1468 return; | 1468 return; |
1469 | 1469 |
1470 if (!allow) | 1470 if (!allow) |
1471 guest->Destroy(); | 1471 guest->Destroy(); |
1472 } | 1472 } |
1473 | 1473 |
1474 void WebViewGuest::OnFullscreenPermissionDecided( | 1474 void WebViewGuest::OnFullscreenPermissionDecided( |
(...skipping 22 matching lines...) Expand all Loading... |
1497 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1497 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1498 DispatchEventToView(base::WrapUnique( | 1498 DispatchEventToView(base::WrapUnique( |
1499 new GuestViewEvent(webview::kEventExitFullscreen, std::move(args)))); | 1499 new GuestViewEvent(webview::kEventExitFullscreen, std::move(args)))); |
1500 } | 1500 } |
1501 // Since we changed fullscreen state, sending a Resize message ensures that | 1501 // Since we changed fullscreen state, sending a Resize message ensures that |
1502 // renderer/ sees the change. | 1502 // renderer/ sees the change. |
1503 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); | 1503 web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); |
1504 } | 1504 } |
1505 | 1505 |
1506 } // namespace extensions | 1506 } // namespace extensions |
OLD | NEW |