|
26 | 26 | #include "content/public/browser/browser_context.h" |
27 | 27 | #include "content/public/browser/browser_thread.h" |
28 | 28 | #include "content/public/browser/child_process_security_policy.h" |
| 29 | +#include "content/public/browser/favicon_status.h" |
29 | 30 | #include "content/public/browser/native_web_keyboard_event.h" |
30 | 31 | #include "content/public/browser/navigation_entry.h" |
31 | 32 | #include "content/public/browser/navigation_handle.h" |
|
44 | 45 | #include "content/public/browser/web_contents.h" |
45 | 46 | #include "content/public/browser/web_contents_delegate.h" |
46 | 47 | #include "content/public/common/browser_side_navigation_policy.h" |
| 48 | +#include "content/public/common/favicon_url.h" |
47 | 49 | #include "content/public/common/media_stream_request.h" |
48 | 50 | #include "content/public/common/page_zoom.h" |
49 | 51 | #include "content/public/common/result_codes.h" |
@@ -355,10 +357,10 @@ void WebViewGuest::CreateWebContents( |
355 | 357 | persist_storage ? "persist" : "", |
356 | 358 | url_encoded_partition.c_str())); |
357 | 359 |
|
358 | | - // If we already have a webview tag in the same app using the same storage |
359 | | - // partition, we should use the same SiteInstance so the existing tag and |
360 | | - // the new tag can script each other. |
361 | | - auto* guest_view_manager = GuestViewManager::FromBrowserContext( |
| 360 | + // If we already have a webview tag in the same app using the same storage |
| 361 | + // partition, we should use the same SiteInstance so the existing tag and |
| 362 | + // the new tag can script each other. |
| 363 | + auto* guest_view_manager = GuestViewManager::FromBrowserContext( |
362 | 364 | owner_render_process_host->GetBrowserContext()); |
363 | 365 | scoped_refptr<content::SiteInstance> guest_site_instance = |
364 | 366 | guest_view_manager->GetGuestSiteInstance(guest_site); |
@@ -534,10 +536,10 @@ void WebViewGuest::WillDestroy() { |
534 | 536 | } |
535 | 537 |
|
536 | 538 | bool WebViewGuest::DidAddMessageToConsole(WebContents* source, |
537 | | - int32_t level, |
538 | | - const base::string16& message, |
539 | | - int32_t line_no, |
540 | | - const base::string16& source_id) { |
| 539 | + int32_t level, |
| 540 | + const base::string16& message, |
| 541 | + int32_t line_no, |
| 542 | + const base::string16& source_id) { |
541 | 543 | std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
542 | 544 | // Log levels are from base/logging.h: LogSeverity. |
543 | 545 | args->SetInteger(webview::kLevel, level); |
@@ -845,6 +847,12 @@ void WebViewGuest::DidFinishNavigation( |
845 | 847 | SetZoom(pending_zoom_factor_); |
846 | 848 | pending_zoom_factor_ = 0.0; |
847 | 849 | } |
| 850 | + |
| 851 | + if ((int)navigation_handle->GetPageTransition() == (int)ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL || |
| 852 | + (int)navigation_handle->GetPageTransition() & (int)ui::PageTransition::PAGE_TRANSITION_FORWARD_BACK) { |
| 853 | + FaviconEvent(web_contents()->GetController().GetEntryAtIndex(web_contents()->GetController().GetCurrentEntryIndex())->GetFavicon().url.spec()); |
| 854 | + TitleWasSet(web_contents()->GetController().GetEntryAtIndex(web_contents()->GetController().GetCurrentEntryIndex()), true); |
| 855 | + } |
848 | 856 | } |
849 | 857 | std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
850 | 858 | args->SetString(guest_view::kUrl, src_.spec()); |
@@ -990,8 +998,8 @@ void WebViewGuest::RemoveWebViewStateFromIOThread( |
990 | 998 | content::BrowserThread::PostTask( |
991 | 999 | content::BrowserThread::IO, FROM_HERE, |
992 | 1000 | base::Bind(&WebViewRendererState::RemoveGuest, |
993 | | - base::Unretained(WebViewRendererState::GetInstance()), |
994 | | - web_contents->GetRenderProcessHost()->GetID(), |
| 1001 | + base::Unretained(WebViewRendererState::GetInstance()), |
| 1002 | + web_contents->GetRenderProcessHost()->GetID(), |
995 | 1003 | web_contents->GetRenderViewHost()->GetRoutingID())); |
996 | 1004 | } |
997 | 1005 |
|
@@ -1183,7 +1191,7 @@ void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) { |
1183 | 1191 | if (!is_pending_new_window) { |
1184 | 1192 | std::string src; |
1185 | 1193 | if (params.GetString(webview::kAttributeSrc, &src)) |
1186 | | - NavigateGuest(src, true /* force_navigation */); |
| 1194 | + NavigateGuest(src, true /* force_navigation */); |
1187 | 1195 | } |
1188 | 1196 | } |
1189 | 1197 |
|
@@ -1415,6 +1423,31 @@ void WebViewGuest::RequestToLockMouse(WebContents* web_contents, |
1415 | 1423 | base::Unretained(web_contents))); |
1416 | 1424 | } |
1417 | 1425 |
|
| 1426 | +void WebViewGuest::FaviconEvent(const std::string& faviconUrl) |
| 1427 | +{ |
| 1428 | + std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1429 | + args->SetString(webview::kFaviconUrl, faviconUrl); |
| 1430 | + DispatchEventToView(base::MakeUnique<GuestViewEvent>(webview::kEventFaviconChange, |
| 1431 | + std::move(args))); |
| 1432 | +} |
| 1433 | + |
| 1434 | +void WebViewGuest::DidUpdateFaviconURL(const std::vector<content::FaviconURL>& candidates) { |
| 1435 | + if (!candidates.empty()) |
| 1436 | + FaviconEvent(candidates[0].icon_url.spec()); |
| 1437 | + else |
| 1438 | + FaviconEvent(""); |
| 1439 | +} |
| 1440 | + |
| 1441 | +void WebViewGuest::TitleWasSet(content::NavigationEntry* entry, bool explicit_set) { |
| 1442 | + if (!entry) |
| 1443 | + return; |
| 1444 | + |
| 1445 | + std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1446 | + args->SetString(webview::kTitle, entry->GetTitleForDisplay()); |
| 1447 | + DispatchEventToView(base::MakeUnique<GuestViewEvent>(webview::kEventTitleChange, |
| 1448 | + std::move(args))); |
| 1449 | +} |
| 1450 | + |
1418 | 1451 | void WebViewGuest::LoadURLWithParams( |
1419 | 1452 | const GURL& url, |
1420 | 1453 | const content::Referrer& referrer, |
|
0 commit comments