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 19 matching lines...) Expand all Loading... | |
369 DispatchEvent( | 383 DispatchEvent( |
370 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); | 384 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); |
371 return true; | 385 return true; |
372 } | 386 } |
373 | 387 |
374 void WebViewGuest::CloseContents(WebContents* source) { | 388 void WebViewGuest::CloseContents(WebContents* source) { |
375 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 389 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
376 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); | 390 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); |
377 } | 391 } |
378 | 392 |
379 void WebViewGuest::DidAttach() { | 393 void WebViewGuest::DidAttach(const base::DictionaryValue& extra_params) { |
394 std::string src; | |
395 if (extra_params.GetString("src", &src) && !src.empty()) { | |
396 printf("DidAttach, src = %s\n", src.c_str()); | |
397 NavigateGuest(src); | |
398 } else { | |
399 printf("DidAttach, no src\n"); | |
400 } | |
401 | |
380 if (GetOpener()) { | 402 if (GetOpener()) { |
381 // We need to do a navigation here if the target URL has changed between | 403 // We need to do a navigation here if the target URL has changed between |
382 // the time the WebContents was created and the time it was attached. | 404 // the time the WebContents was created and the time it was attached. |
383 // We also need to do an initial navigation if a RenderView was never | 405 // We also need to do an initial navigation if a RenderView was never |
384 // created for the new window in cases where there is no referrer. | 406 // created for the new window in cases where there is no referrer. |
385 PendingWindowMap::iterator it = | 407 PendingWindowMap::iterator it = |
386 GetOpener()->pending_new_windows_.find(this); | 408 GetOpener()->pending_new_windows_.find(this); |
387 if (it != GetOpener()->pending_new_windows_.end()) { | 409 if (it != GetOpener()->pending_new_windows_.end()) { |
388 const NewWindowInfo& new_window_info = it->second; | 410 const NewWindowInfo& new_window_info = it->second; |
389 NavigateGuest(new_window_info.url.spec()); | 411 NavigateGuest(new_window_info.url.spec()); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 const content::OpenURLParams& params) { | 521 const content::OpenURLParams& params) { |
500 GuestViewManager* guest_manager = | 522 GuestViewManager* guest_manager = |
501 GuestViewManager::FromBrowserContext(browser_context()); | 523 GuestViewManager::FromBrowserContext(browser_context()); |
502 // Allocate a new instance ID for the new guest. | 524 // Allocate a new instance ID for the new guest. |
503 int instance_id = guest_manager->GetNextInstanceID(); | 525 int instance_id = guest_manager->GetNextInstanceID(); |
504 | 526 |
505 // Set the attach params to use the same partition as the opener. | 527 // Set the attach params to use the same partition as the opener. |
506 // We pull the partition information from the site's URL, which is of the | 528 // We pull the partition information from the site's URL, which is of the |
507 // form guest://site/{persist}?{partition_name}. | 529 // form guest://site/{persist}?{partition_name}. |
508 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); | 530 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); |
531 scoped_ptr<base::DictionaryValue> create_params(extra_params()->DeepCopy()); | |
532 const std::string storage_partition_id = | |
533 GetStoragePartitionIdFromSiteURL(site_url); | |
534 create_params->SetString(guestview::kStoragePartitionId, | |
535 storage_partition_id); | |
509 | 536 |
510 scoped_ptr<base::DictionaryValue> create_params(extra_params()->DeepCopy()); | |
511 const std::string& storage_partition_id = site_url.query(); | |
512 bool persist_storage = | |
513 site_url.path().find("persist") != std::string::npos; | |
514 WebContents* new_guest_web_contents = | 537 WebContents* new_guest_web_contents = |
515 guest_manager->CreateGuest(guest_web_contents()->GetSiteInstance(), | 538 guest_manager->CreateGuest(guest_web_contents()->GetSiteInstance(), |
516 instance_id, | 539 instance_id, |
517 storage_partition_id, | |
518 persist_storage, | |
519 create_params.Pass()); | 540 create_params.Pass()); |
520 WebViewGuest* new_guest = | 541 WebViewGuest* new_guest = |
521 WebViewGuest::FromWebContents(new_guest_web_contents); | 542 WebViewGuest::FromWebContents(new_guest_web_contents); |
522 new_guest->SetOpener(this); | 543 new_guest->SetOpener(this); |
523 | 544 |
524 // Take ownership of |new_guest|. | 545 // Take ownership of |new_guest|. |
525 pending_new_windows_.insert( | 546 pending_new_windows_.insert( |
526 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); | 547 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); |
527 | 548 |
528 // Request permission to show the new window. | 549 // Request permission to show the new window. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 806 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
786 GURL(), | 807 GURL(), |
787 content::StoragePartition::OriginMatcherFunction(), | 808 content::StoragePartition::OriginMatcherFunction(), |
788 remove_since, | 809 remove_since, |
789 base::Time::Now(), | 810 base::Time::Now(), |
790 callback); | 811 callback); |
791 return true; | 812 return true; |
792 } | 813 } |
793 | 814 |
794 WebViewGuest::~WebViewGuest() { | 815 WebViewGuest::~WebViewGuest() { |
816 printf("++++ %s\n", __PRETTY_FUNCTION__); | |
795 } | 817 } |
796 | 818 |
797 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 819 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
798 int64 frame_id, | 820 int64 frame_id, |
799 const base::string16& frame_unique_name, | 821 const base::string16& frame_unique_name, |
800 bool is_main_frame, | 822 bool is_main_frame, |
801 const GURL& url, | 823 const GURL& url, |
802 content::PageTransition transition_type, | 824 content::PageTransition transition_type, |
803 content::RenderViewHost* render_view_host) { | 825 content::RenderViewHost* render_view_host) { |
804 find_helper_.CancelAllFindSessions(); | 826 find_helper_.CancelAllFindSessions(); |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1234 : callback(callback), | 1256 : callback(callback), |
1235 permission_type(permission_type), | 1257 permission_type(permission_type), |
1236 allowed_by_default(allowed_by_default) { | 1258 allowed_by_default(allowed_by_default) { |
1237 } | 1259 } |
1238 | 1260 |
1239 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | 1261 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { |
1240 } | 1262 } |
1241 | 1263 |
1242 void WebViewGuest::ShowContextMenu(int request_id, | 1264 void WebViewGuest::ShowContextMenu(int request_id, |
1243 const MenuItemVector* items) { | 1265 const MenuItemVector* items) { |
1266 printf("++++ %s\n", __PRETTY_FUNCTION__); | |
1244 if (!pending_menu_.get()) | 1267 if (!pending_menu_.get()) |
1245 return; | 1268 return; |
1246 | 1269 |
1247 // Make sure this was the correct request. | 1270 // Make sure this was the correct request. |
1248 if (request_id != pending_context_menu_request_id_) | 1271 if (request_id != pending_context_menu_request_id_) |
1249 return; | 1272 return; |
1250 | 1273 |
1251 // TODO(lazyboy): Implement. | 1274 // TODO(lazyboy): Implement. |
1252 DCHECK(!items); | 1275 DCHECK(!items); |
1253 | 1276 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1348 bool user_gesture, | 1371 bool user_gesture, |
1349 content::WebContents* new_contents) { | 1372 content::WebContents* new_contents) { |
1350 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); | 1373 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); |
1351 if (!guest) | 1374 if (!guest) |
1352 return; | 1375 return; |
1353 PendingWindowMap::iterator it = pending_new_windows_.find(guest); | 1376 PendingWindowMap::iterator it = pending_new_windows_.find(guest); |
1354 if (it == pending_new_windows_.end()) | 1377 if (it == pending_new_windows_.end()) |
1355 return; | 1378 return; |
1356 const NewWindowInfo& new_window_info = it->second; | 1379 const NewWindowInfo& new_window_info = it->second; |
1357 | 1380 |
1381 printf("Begin RequestNewWindowPermission\n"); | |
1382 printf("Try new contents\n"); | |
1383 // Retrieve the opener partition info if we have it. | |
1384 const GURL& site_url = new_contents->GetSiteInstance()->GetSiteURL(); | |
1385 std::string storage_partition_id = GetStoragePartitionIdFromSiteURL(site_url); | |
1386 | |
1358 base::DictionaryValue request_info; | 1387 base::DictionaryValue request_info; |
1359 request_info.Set(webview::kInitialHeight, | 1388 request_info.Set(webview::kInitialHeight, |
1360 base::Value::CreateIntegerValue(initial_bounds.height())); | 1389 base::Value::CreateIntegerValue(initial_bounds.height())); |
1361 request_info.Set(webview::kInitialWidth, | 1390 request_info.Set(webview::kInitialWidth, |
1362 base::Value::CreateIntegerValue(initial_bounds.width())); | 1391 base::Value::CreateIntegerValue(initial_bounds.width())); |
1363 request_info.Set(webview::kTargetURL, | 1392 request_info.Set(webview::kTargetURL, |
1364 base::Value::CreateStringValue(new_window_info.url.spec())); | 1393 base::Value::CreateStringValue(new_window_info.url.spec())); |
1365 request_info.Set(webview::kName, | 1394 request_info.Set(webview::kName, |
1366 base::Value::CreateStringValue(new_window_info.name)); | 1395 base::Value::CreateStringValue(new_window_info.name)); |
1367 request_info.Set(webview::kWindowID, | 1396 request_info.Set(webview::kWindowID, |
1368 base::Value::CreateIntegerValue(guest->guest_instance_id())); | 1397 base::Value::CreateIntegerValue(guest->guest_instance_id())); |
1398 request_info.Set(guestview::kStoragePartitionId, | |
Fady Samuel
2014/05/29 20:35:23
Comment explaining why we need to send the partiti
lazyboy
2014/05/30 05:48:21
Done.
| |
1399 base::Value::CreateStringValue(storage_partition_id)); | |
1369 request_info.Set(webview::kWindowOpenDisposition, | 1400 request_info.Set(webview::kWindowOpenDisposition, |
1370 base::Value::CreateStringValue( | 1401 base::Value::CreateStringValue( |
1371 WindowOpenDispositionToString(disposition))); | 1402 WindowOpenDispositionToString(disposition))); |
1372 | 1403 |
1373 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, | 1404 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
1374 request_info, | 1405 request_info, |
1375 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, | 1406 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
1376 base::Unretained(this), | 1407 base::Unretained(this), |
1377 guest->guest_instance_id()), | 1408 guest->guest_instance_id()), |
1378 false /* allowed_by_default */); | 1409 false /* allowed_by_default */); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1410 bool allow, | 1441 bool allow, |
1411 const std::string& user_input) { | 1442 const std::string& user_input) { |
1412 WebViewGuest* guest = | 1443 WebViewGuest* guest = |
1413 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1444 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1414 if (!guest) | 1445 if (!guest) |
1415 return; | 1446 return; |
1416 | 1447 |
1417 if (!allow) | 1448 if (!allow) |
1418 guest->Destroy(); | 1449 guest->Destroy(); |
1419 } | 1450 } |
OLD | NEW |