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 "chrome/browser/guest_view/web_view/web_view_guest.h" | 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
6 | 6 |
7 #include "base/debug/stack_trace.h" | 7 #include "base/debug/stack_trace.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | 133 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
134 return webview::kPermissionTypeNewWindow; | 134 return webview::kPermissionTypeNewWindow; |
135 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | 135 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: |
136 return webview::kPermissionTypePointerLock; | 136 return webview::kPermissionTypePointerLock; |
137 default: | 137 default: |
138 NOTREACHED(); | 138 NOTREACHED(); |
139 return std::string(); | 139 return std::string(); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { | |
144 const std::string& partition_id = site_url.query(); | |
145 bool persist_storage = site_url.path().find("persist") != std::string::npos; | |
146 | |
147 printf("site_url: %s\n", site_url.possibly_invalid_spec().c_str()); | |
148 printf("partition would be: %s\n", site_url.query().c_str()); | |
149 printf("extracted: id: %s, persist_storage: %d\n", | |
150 partition_id.c_str(), persist_storage); | |
151 | |
152 return (persist_storage ? webview::kPersistPrefix : "") + partition_id; | |
153 } | |
154 | |
143 void RemoveWebViewEventListenersOnIOThread( | 155 void RemoveWebViewEventListenersOnIOThread( |
144 void* profile, | 156 void* profile, |
145 const std::string& extension_id, | 157 const std::string& extension_id, |
146 int embedder_process_id, | 158 int embedder_process_id, |
147 int view_instance_id) { | 159 int view_instance_id) { |
148 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 160 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
149 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( | 161 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( |
150 profile, | 162 profile, |
151 extension_id, | 163 extension_id, |
152 embedder_process_id, | 164 embedder_process_id, |
(...skipping 29 matching lines...) Expand all Loading... | |
182 script_executor_(new extensions::ScriptExecutor(guest_web_contents, | 194 script_executor_(new extensions::ScriptExecutor(guest_web_contents, |
183 &script_observers_)), | 195 &script_observers_)), |
184 pending_context_menu_request_id_(0), | 196 pending_context_menu_request_id_(0), |
185 next_permission_request_id_(0), | 197 next_permission_request_id_(0), |
186 is_overriding_user_agent_(false), | 198 is_overriding_user_agent_(false), |
187 pending_reload_on_attachment_(false), | 199 pending_reload_on_attachment_(false), |
188 main_frame_id_(0), | 200 main_frame_id_(0), |
189 chromevox_injected_(false), | 201 chromevox_injected_(false), |
190 find_helper_(this), | 202 find_helper_(this), |
191 javascript_dialog_helper_(this) { | 203 javascript_dialog_helper_(this) { |
204 printf("++++ %s\n", __PRETTY_FUNCTION__); | |
192 notification_registrar_.Add( | 205 notification_registrar_.Add( |
193 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 206 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
194 content::Source<WebContents>(guest_web_contents)); | 207 content::Source<WebContents>(guest_web_contents)); |
195 | 208 |
196 notification_registrar_.Add( | 209 notification_registrar_.Add( |
197 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 210 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
198 content::Source<WebContents>(guest_web_contents)); | 211 content::Source<WebContents>(guest_web_contents)); |
199 | 212 |
200 #if defined(OS_CHROMEOS) | 213 #if defined(OS_CHROMEOS) |
201 chromeos::AccessibilityManager* accessibility_manager = | 214 chromeos::AccessibilityManager* accessibility_manager = |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 SetUserAgentOverride(""); | 343 SetUserAgentOverride(""); |
331 } | 344 } |
332 | 345 |
333 GuestViewBase::Attach(embedder_web_contents, args); | 346 GuestViewBase::Attach(embedder_web_contents, args); |
334 | 347 |
335 AddWebViewToExtensionRendererState(); | 348 AddWebViewToExtensionRendererState(); |
336 } | 349 } |
337 | 350 |
338 bool WebViewGuest::HandleContextMenu( | 351 bool WebViewGuest::HandleContextMenu( |
339 const content::ContextMenuParams& params) { | 352 const content::ContextMenuParams& params) { |
353 printf("++++ %s\n", __PRETTY_FUNCTION__); | |
340 ContextMenuDelegate* menu_delegate = | 354 ContextMenuDelegate* menu_delegate = |
341 ContextMenuDelegate::FromWebContents(guest_web_contents()); | 355 ContextMenuDelegate::FromWebContents(guest_web_contents()); |
342 DCHECK(menu_delegate); | 356 DCHECK(menu_delegate); |
343 | 357 |
344 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); | 358 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); |
345 | 359 |
346 // Pass it to embedder. | 360 // Pass it to embedder. |
347 int request_id = ++pending_context_menu_request_id_; | 361 int request_id = ++pending_context_menu_request_id_; |
348 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 362 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
349 scoped_ptr<base::ListValue> items = | 363 scoped_ptr<base::ListValue> items = |
(...skipping 17 matching lines...) Expand all Loading... | |
367 args->SetString(webview::kSourceId, source_id); | 381 args->SetString(webview::kSourceId, source_id); |
368 DispatchEvent( | 382 DispatchEvent( |
369 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); | 383 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); |
370 } | 384 } |
371 | 385 |
372 void WebViewGuest::Close() { | 386 void WebViewGuest::Close() { |
373 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 387 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
374 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); | 388 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); |
375 } | 389 } |
376 | 390 |
377 void WebViewGuest::DidAttach() { | 391 void WebViewGuest::DidAttach(const base::DictionaryValue& extra_params) { |
392 std::string src; | |
393 if (extra_params.GetString("src", &src) && !src.empty()) { | |
394 printf("DidAttach, src = %s\n", src.c_str()); | |
395 NavigateGuest(src); | |
396 } else { | |
397 printf("DidAttach, no src\n"); | |
398 } | |
399 | |
378 if (GetOpener()) { | 400 if (GetOpener()) { |
379 // We need to do a navigation here if the target URL has changed between | 401 // We need to do a navigation here if the target URL has changed between |
380 // the time the WebContents was created and the time it was attached. | 402 // the time the WebContents was created and the time it was attached. |
381 // We also need to do an initial navigation if a RenderView was never | 403 // We also need to do an initial navigation if a RenderView was never |
382 // created for the new window in cases where there is no referrer. | 404 // created for the new window in cases where there is no referrer. |
383 PendingWindowMap::iterator it = | 405 PendingWindowMap::iterator it = |
384 GetOpener()->pending_new_windows_.find(this); | 406 GetOpener()->pending_new_windows_.find(this); |
385 if (it != GetOpener()->pending_new_windows_.end()) { | 407 if (it != GetOpener()->pending_new_windows_.end()) { |
386 const NewWindowInfo& new_window_info = it->second; | 408 const NewWindowInfo& new_window_info = it->second; |
387 NavigateGuest(new_window_info.url.spec()); | 409 NavigateGuest(new_window_info.url.spec()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 } | 513 } |
492 | 514 |
493 WebViewGuest* WebViewGuest::CreateNewGuestWindow( | 515 WebViewGuest* WebViewGuest::CreateNewGuestWindow( |
494 const content::OpenURLParams& params) { | 516 const content::OpenURLParams& params) { |
495 | 517 |
496 GuestViewManager* guest_manager = | 518 GuestViewManager* guest_manager = |
497 GuestViewManager::FromBrowserContext(browser_context()); | 519 GuestViewManager::FromBrowserContext(browser_context()); |
498 // Allocate a new instance ID for the new guest. | 520 // Allocate a new instance ID for the new guest. |
499 int instance_id = guest_manager->GetNextInstanceID(); | 521 int instance_id = guest_manager->GetNextInstanceID(); |
500 | 522 |
523 // TODO(lazyboy): This codepath doesn't seem to tested by our tests. | |
Fady Samuel
2014/05/27 14:19:06
This code comes from middle click or ctrl+click. I
lazyboy
2014/05/27 20:43:00
Ya you're right, WebViewInteractiveTest.NewWindow_
| |
501 // Set the attach params to use the same partition as the opener. | 524 // Set the attach params to use the same partition as the opener. |
502 // We pull the partition information from the site's URL, which is of the | 525 // We pull the partition information from the site's URL, which is of the |
503 // form guest://site/{persist}?{partition_name}. | 526 // form guest://site/{persist}?{partition_name}. |
504 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); | 527 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); |
528 scoped_ptr<base::DictionaryValue> create_params(extra_params()->DeepCopy()); | |
529 const std::string storage_partition_id = | |
530 GetStoragePartitionIdFromSiteURL(site_url); | |
531 create_params->SetString(guestview::kStoragePartitionId, | |
532 storage_partition_id); | |
505 | 533 |
506 scoped_ptr<base::DictionaryValue> create_params(extra_params()->DeepCopy()); | |
507 const std::string& storage_partition_id = site_url.query(); | |
508 bool persist_storage = | |
509 site_url.path().find("persist") != std::string::npos; | |
510 WebContents* new_guest_web_contents = | 534 WebContents* new_guest_web_contents = |
511 guest_manager->CreateGuest(guest_web_contents()->GetSiteInstance(), | 535 guest_manager->CreateGuest(guest_web_contents()->GetSiteInstance(), |
512 instance_id, | 536 instance_id, |
513 storage_partition_id, | |
514 persist_storage, | |
515 create_params.Pass()); | 537 create_params.Pass()); |
516 WebViewGuest* new_guest = | 538 WebViewGuest* new_guest = |
517 WebViewGuest::FromWebContents(new_guest_web_contents); | 539 WebViewGuest::FromWebContents(new_guest_web_contents); |
518 new_guest->SetOpener(this); | 540 new_guest->SetOpener(this); |
519 | 541 |
520 // Take ownership of |new_guest|. | 542 // Take ownership of |new_guest|. |
521 pending_new_windows_.insert( | 543 pending_new_windows_.insert( |
522 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); | 544 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); |
523 | 545 |
524 // Request permission to show the new window. | 546 // Request permission to show the new window. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 803 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
782 GURL(), | 804 GURL(), |
783 content::StoragePartition::OriginMatcherFunction(), | 805 content::StoragePartition::OriginMatcherFunction(), |
784 remove_since, | 806 remove_since, |
785 base::Time::Now(), | 807 base::Time::Now(), |
786 callback); | 808 callback); |
787 return true; | 809 return true; |
788 } | 810 } |
789 | 811 |
790 WebViewGuest::~WebViewGuest() { | 812 WebViewGuest::~WebViewGuest() { |
813 printf("++++ %s\n", __PRETTY_FUNCTION__); | |
791 } | 814 } |
792 | 815 |
793 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 816 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
794 int64 frame_id, | 817 int64 frame_id, |
795 const base::string16& frame_unique_name, | 818 const base::string16& frame_unique_name, |
796 bool is_main_frame, | 819 bool is_main_frame, |
797 const GURL& url, | 820 const GURL& url, |
798 content::PageTransition transition_type, | 821 content::PageTransition transition_type, |
799 content::RenderViewHost* render_view_host) { | 822 content::RenderViewHost* render_view_host) { |
800 find_helper_.CancelAllFindSessions(); | 823 find_helper_.CancelAllFindSessions(); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1228 : callback(callback), | 1251 : callback(callback), |
1229 permission_type(permission_type), | 1252 permission_type(permission_type), |
1230 allowed_by_default(allowed_by_default) { | 1253 allowed_by_default(allowed_by_default) { |
1231 } | 1254 } |
1232 | 1255 |
1233 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | 1256 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { |
1234 } | 1257 } |
1235 | 1258 |
1236 void WebViewGuest::ShowContextMenu(int request_id, | 1259 void WebViewGuest::ShowContextMenu(int request_id, |
1237 const MenuItemVector* items) { | 1260 const MenuItemVector* items) { |
1261 printf("++++ %s\n", __PRETTY_FUNCTION__); | |
1238 if (!pending_menu_.get()) | 1262 if (!pending_menu_.get()) |
1239 return; | 1263 return; |
1240 | 1264 |
1241 // Make sure this was the correct request. | 1265 // Make sure this was the correct request. |
1242 if (request_id != pending_context_menu_request_id_) | 1266 if (request_id != pending_context_menu_request_id_) |
1243 return; | 1267 return; |
1244 | 1268 |
1245 // TODO(lazyboy): Implement. | 1269 // TODO(lazyboy): Implement. |
1246 DCHECK(!items); | 1270 DCHECK(!items); |
1247 | 1271 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1342 bool user_gesture, | 1366 bool user_gesture, |
1343 content::WebContents* new_contents) { | 1367 content::WebContents* new_contents) { |
1344 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); | 1368 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); |
1345 if (!guest) | 1369 if (!guest) |
1346 return; | 1370 return; |
1347 PendingWindowMap::iterator it = pending_new_windows_.find(guest); | 1371 PendingWindowMap::iterator it = pending_new_windows_.find(guest); |
1348 if (it == pending_new_windows_.end()) | 1372 if (it == pending_new_windows_.end()) |
1349 return; | 1373 return; |
1350 const NewWindowInfo& new_window_info = it->second; | 1374 const NewWindowInfo& new_window_info = it->second; |
1351 | 1375 |
1376 printf("Begin RequestNewWindowPermission\n"); | |
1377 printf("Try new contents\n"); | |
1378 // Retrieve the opener partition info if we have it. | |
1379 const GURL& site_url = new_contents->GetSiteInstance()->GetSiteURL(); | |
1380 std::string storage_partition_id = GetStoragePartitionIdFromSiteURL(site_url); | |
1381 | |
1352 base::DictionaryValue request_info; | 1382 base::DictionaryValue request_info; |
1353 request_info.Set(webview::kInitialHeight, | 1383 request_info.Set(webview::kInitialHeight, |
1354 base::Value::CreateIntegerValue(initial_bounds.height())); | 1384 base::Value::CreateIntegerValue(initial_bounds.height())); |
1355 request_info.Set(webview::kInitialWidth, | 1385 request_info.Set(webview::kInitialWidth, |
1356 base::Value::CreateIntegerValue(initial_bounds.width())); | 1386 base::Value::CreateIntegerValue(initial_bounds.width())); |
1357 request_info.Set(webview::kTargetURL, | 1387 request_info.Set(webview::kTargetURL, |
1358 base::Value::CreateStringValue(new_window_info.url.spec())); | 1388 base::Value::CreateStringValue(new_window_info.url.spec())); |
1359 request_info.Set(webview::kName, | 1389 request_info.Set(webview::kName, |
1360 base::Value::CreateStringValue(new_window_info.name)); | 1390 base::Value::CreateStringValue(new_window_info.name)); |
1361 request_info.Set(webview::kWindowID, | 1391 request_info.Set(webview::kWindowID, |
1362 base::Value::CreateIntegerValue(guest->guest_instance_id())); | 1392 base::Value::CreateIntegerValue(guest->guest_instance_id())); |
1393 request_info.Set(guestview::kStoragePartitionId, | |
1394 base::Value::CreateStringValue(storage_partition_id)); | |
1363 request_info.Set(webview::kWindowOpenDisposition, | 1395 request_info.Set(webview::kWindowOpenDisposition, |
1364 base::Value::CreateStringValue( | 1396 base::Value::CreateStringValue( |
1365 WindowOpenDispositionToString(disposition))); | 1397 WindowOpenDispositionToString(disposition))); |
1366 | 1398 |
1367 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, | 1399 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
1368 request_info, | 1400 request_info, |
1369 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, | 1401 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
1370 base::Unretained(this), | 1402 base::Unretained(this), |
1371 guest->guest_instance_id()), | 1403 guest->guest_instance_id()), |
1372 false /* allowed_by_default */); | 1404 false /* allowed_by_default */); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1404 bool allow, | 1436 bool allow, |
1405 const std::string& user_input) { | 1437 const std::string& user_input) { |
1406 WebViewGuest* guest = | 1438 WebViewGuest* guest = |
1407 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1439 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1408 if (!guest) | 1440 if (!guest) |
1409 return; | 1441 return; |
1410 | 1442 |
1411 if (!allow) | 1443 if (!allow) |
1412 guest->Destroy(); | 1444 guest->Destroy(); |
1413 } | 1445 } |
OLD | NEW |