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